标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1225 Accepted Submission(s):
730
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 }
标签:
原文地址:http://www.cnblogs.com/pshw/p/5547393.html