Problem of Precision
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1226 Accepted Submission(s): 731
Problem Description
![](https://i-blog.csdnimg.cn/blog_migrate/452366445ca2fdd383e1e9275ee65a60.jpeg)
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
#include <bits/stdc++.h>
using namespace std;
int Mod=1024;
struct Matrix
{
int ma[2][2];
Matrix(){
memset(ma,0,sizeof(ma));
}
void init(int a,int b,int c,int d){
ma[0][0]=a;ma[0][1]=b;
ma[1][0]=c;ma[1][1]=d;
}
Matrix operator * (const Matrix &m)
{
Matrix res;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
res.ma[i][j]=(res.ma[i][j]+ma[i][k]*m.ma[k][j])%Mod;
return res;
}
};
Matrix quick_pow(Matrix m,int n)
{
if(n==1)return m;
Matrix res=quick_pow(m,n/2);
Matrix ans=res*res;
if(n%2==1)
ans=ans*m;
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
Matrix m,res;
m.init(5,2,12,5);
res=quick_pow(m,n);
printf("%d\n",(2*res.ma[0][0]-1)%Mod);
}
return 0;
}