https://vjudge.net/contest/360957#problem/J
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Matrix{ int m[2][2]; }; Matrix mul(Matrix a,Matrix b){ Matrix ans; for(int i = 0; i < 2; i++){ for(int j = 0; j < 2; j++){ ans.m[i][j] = 0; for(int k = 0; k < 2; k++){ ans.m[i][j] = (ans.m[i][j] + a.m[i][k] * b.m[k][j] % 7) % 7; } } } return ans; } int main(){ int A,B,n; while(scanf("%d%d%d",&A,&B,&n) != EOF){ if(A == 0 && B == 0 && n == 0) break; if(n <= 2){ printf("1\n"); continue; } Matrix a,ans; a.m[0][0] = A; a.m[0][1] = B; a.m[1][0] = 1; a.m[1][1] = 0; ans.m[0][0] = ans.m[1][1] = 1; ans.m[0][1] = ans.m[1][0] = 0; n -= 2; while(n){ if(n & 1) ans = mul(ans,a); n >>= 1; a = mul(a,a); } printf("%d\n",(ans.m[0][0] + ans.m[0][1]) % 7); } return 0; }
原文链接: https://www.cnblogs.com/SunChuangYu/p/12459834.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/372250
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!