标签:解题思路 line esc process struct integer clu 简单 cin
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 236241 Accepted Submission(s): 60070
#include<iostream> #include<cstdio> #include<cstring> #define mem(a) memset(a,0,sizeof(a)) #define forn(i,n) for(int i=0;i<n;++i) #define for1(i,n) for(int i=1;i<=n;++i) #define IO std::ios::sync_with_stdio(false); std::cin.tie(0) using namespace std; typedef long long ll; const int maxn=30; const int mod=7; const int inf=0x3f3f3f3f; int n,m,k,t,x,y; struct Matrix { int val[2][2]; }; Matrix E= {1,0, 0,1 }; Matrix Multiply(Matrix a,Matrix b) { Matrix ans=E; forn(i,2) forn(j,2) { int temp=0; forn(k,2) temp=(temp+a.val[i][k]*b.val[k][j]%mod)%mod; ans.val[i][j]=temp; } return ans; } int quick_pow(Matrix a,int n) { Matrix res=E; while(n>0) { if(n&1) res=Multiply(res,a); a=Multiply(a,a); n>>=1; } int ans=0; ans=(res.val[0][0]+res.val[0][1])%mod; return ans; } int main(){ IO; while(cin>>x>>y>>n) { if(x==y&&n==x&&x==0) break; Matrix t= { x,y, 1,0 }; int ans=(quick_pow(t,n-2))%mod; cout<<ans<<endl; } return 0; }
HDU 1005 Number Sequence 矩阵快速幂
标签:解题思路 line esc process struct integer clu 简单 cin
原文地址:https://www.cnblogs.com/bethebestone/p/12402048.html