Problem of Precision
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1057 Accepted Submission(s): 624
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
解法参考 http://blog.youkuaiyun.com/qq_15714857/article/details/47705581
代码如下:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define mod 1024
struct Node{
int a[2][2];
Node(){
memset(a,0,sizeof(a));
}
Node operator * (const Node & b){
Node c;
memset(c.a,0,sizeof(c.a));
for(int i = 0;i < 2; i++)
for(int j = 0;j < 2; j++)
for(int k = 0;k < 2; k++)
c.a[i][j] = (c.a[i][j]+a[i][k]*b.a[k][j])%mod;
return c;
}
};
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
Node a,b,c;
a.a[0][0] = 5;
a.a[0][1] = 12;
a.a[1][0] = 2;
a.a[1][1] = 5;
b.a[0][0] = 1;
while(n){
if(n&1)b = b*a;
a = a*a;
n/=2;
}
int ans = b.a[0][0]*2-1;
printf("%d\n",ans%mod);
}
return 0;
}