码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 2256 Problem of Precision

时间:2016-05-31 22:10:17      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

Problem of Precision

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1225    Accepted Submission(s): 730


Problem Description
技术分享
 

 

Input
The first line of input gives the number of cases, T. T test cases follow, each on a separate line. Each test case contains one positive integer n. (1 <= n <= 10^9)
 

 

Output
For each input case, you should output the answer in one line.
 

 

Sample Input
3
1
2
5
 

 

Sample Output
9
97
841
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  3117 2254 1588 2294 2276 
 
按照题意推就是的,代码很简单,关键是推理过程。贴一段别人的思路:
技术分享
 
题意:给出一个式子,求值。
 
附上代码:
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #define mod 1024
 5 using namespace std;
 6 struct mat
 7 {
 8     int m[2][2];
 9 };
10 
11 mat mul(mat a,mat b)
12 {
13     mat c;
14     int i,j,k;
15     memset(c.m,0,sizeof(c.m));
16     for(i=0; i<2; i++)
17         for(j=0; j<2; j++)
18         {
19             for(k=0; k<2; k++)
20                 c.m[i][j]+=(a.m[i][k]*b.m[k][j])%mod;
21             c.m[i][j]%=mod;
22         }
23     return c;
24 }
25 
26 mat product(mat a,int k)
27 {
28     if(k==1) return a;
29     else if(k&1) return mul(product(a,k-1),a);
30     else return product(mul(a,a),k/2);
31 }
32 
33 int main()
34 {
35     int T,i,j,n,m;
36     mat a,b;
37     scanf("%d",&T);
38     while(T--)
39     {
40         scanf("%d",&n);
41         if(n==1)
42         {
43             printf("9\n");
44             continue;
45         }
46         a.m[0][0]=5;
47         a.m[0][1]=12;
48         a.m[1][0]=2;
49         a.m[1][1]=5;
50         b=product(a,n-1);
51         int ans=(b.m[0][0]*5+b.m[0][1]*2)%mod;
52         ans=(ans*2-1)%mod;
53         printf("%d\n",ans);
54     }
55     return 0;
56 }

 

hdu 2256 Problem of Precision

标签:

原文地址:http://www.cnblogs.com/pshw/p/5547393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!