标签:get 怎样 str 关系 href ali 代码 code ++
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842
题目:
1 #include <cstdio> 2 #include <cstring> 3 4 typedef long long ll; 5 const int mod = 200907; 6 int n; 7 int f[3], a[3][3]; 8 9 void mul(int f[3], int a[3][3]) { 10 int c[3]; 11 memset(c, 0, sizeof(c)); 12 for(int i = 0; i < 3; i++) { 13 for(int j = 0; j < 3; j++) { 14 c[i] = (c[i] + (ll) f[j] * a[j][i]) % mod; 15 } 16 } 17 memcpy(f, c, sizeof(c)); 18 } 19 20 void mulself(int a[3][3]) { 21 int c[3][3]; 22 memset(c, 0, sizeof(c)); 23 for(int i = 0; i < 3; i++) { 24 for(int j = 0; j < 3; j++) { 25 for(int k = 0; k < 3; k++) { 26 c[i][j] = (c[i][j] + (ll) a[i][k] * a[k][j]) % mod; 27 } 28 } 29 } 30 memcpy(a, c, sizeof(c)); 31 } 32 33 int main() { 34 while(~scanf("%d", &n) && n) { 35 if(n == 1) { 36 printf("1\n"); 37 continue; 38 } 39 if(n == 2) { 40 printf("2\n"); 41 continue; 42 } 43 f[0] = 2, f[1] = 1, f[2] = 1; 44 a[0][0] = 1, a[0][1] = 1, a[0][2] = 0; 45 a[1][0] = 2, a[1][1] = 0, a[1][2] = 0; 46 a[2][0] = 1, a[2][1] = 0, a[2][2] = 1; 47 n = n - 2; 48 for(; n; n >>= 1) { 49 if(n & 1) mul(f, a); 50 mulself(a); 51 } 52 printf("%d\n", f[0] % mod); 53 } 54 return 0; 55 }
标签:get 怎样 str 关系 href ali 代码 code ++
原文地址:https://www.cnblogs.com/Dillonh/p/8972145.html