http://acm.hdu.edu.cn/showproblem.php?pid=1005
2010-08-06 15:59
295 查看
]#include <iostream> #include <cstring> #include <cstdio> using namespace std; const int N = 2; const int mod = 7; struct Mat { int num ; Mat() { for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) num[i][j] = 0; } }; Mat mal(Mat a, Mat b) { Mat r; for(int i = 0; i < N; i++) for(int k = 0; k < N; k++) if(a.num[i][k]) for(int j = 0; j < N; j++) if(b.num[k][j]) r.num[i][j] = (r.num[i][j] + a.num[i][k]* b.num[k][j]) % mod; return r; } Mat mul(Mat a, Mat b, int n) { while(n) { if(n & 1) { n--; b = mal(a, b); } else { n >>= 1; a = mal(a, a); } } return b; } int main() { int a, b, n; while( scanf("%d %d %d", &a, &b, &n) != EOF && a + b + n) { if(n <= 2) { puts("1"); continue; } Mat init, unit, ans; init.num[0][0] = a; init.num[0][1]= b; init.num[1][0] = 1; unit.num[0][0] = 1; unit.num[1][0] = 1; ans = mul(init, unit, n - 2); printf("%d/n", ans.num[0][0]); } return 0; }
相关文章推荐
- Number Sequence&&http://acm.hdu.edu.cn/showproblem.php?pid=1005
- Number Sequence(http://acm.hdu.edu.cn/showproblem.php?pid=1005)
- http://acm.hdu.edu.cn/showproblem.php?pid=3015 树状数组
- http://acm.hdu.edu.cn/showproblem.php?pid=1087
- 又见GCD(http://acm.hdu.edu.cn/showproblem.php?pid=2504)
- Advanced Fruits(链接:http://acm.hdu.edu.cn/showproblem.php?pid=1503)
- HDU 2544 最短路 http://acm.hdu.edu.cn/showproblem.php?pid=2544
- http://acm.hdu.edu.cn/showproblem.php?pid=1247
- http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理
- http://acm.hdu.edu.cn/showproblem.php?pid=1039..借鉴了别人的一些方法。。
- http://acm.hdu.edu.cn/showproblem.php?pid=1710
- http://acm.hdu.edu.cn/showproblem.php?pid=1541
- 二维背包:http://acm.hdu.edu.cn/showproblem.php?pid=3303
- http://acm.hdu.edu.cn/showproblem.php?pid=1542 矩形面积的并 线段树 + 扫描线 + 离散化
- http://acm.hdu.edu.cn/showproblem.php?pid=1010
- http://acm.hdu.edu.cn/showproblem.php?pid=2688 数状数组 线段树
- Robberies&&http://acm.hdu.edu.cn/showproblem.php?pid=2955
- HDU Today&&http://acm.hdu.edu.cn/showproblem.php?pid=2112
- http://acm.hdu.edu.cn/showproblem.php?pid=1003
- http://acm.hdu.edu.cn/showproblem.php?pid=1506