标签:
Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
Sample Output
Source
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define mod 1000000006 #define mod2 1000000007 typedef long long ll; struct matrix { ll data[2][2]; }; matrix I= {1,0,0,1}; matrix multi(matrix a,matrix b) { matrix c; memset(c.data,0,sizeof(c.data)); for(int i=0; i<2; i++) for(int j=0; j<2; j++) for(int k=0; k<2; k++) { c.data[i][j]+=(a.data[i][k]%mod)*(b.data[k][j]%mod); c.data[i][j]%=mod; } return c; } matrix pow(matrix a,ll b) { matrix ans=I; while(b) { if(b&1) { ans=multi(ans,a); b--; } b>>=1; a=multi(a,a); } return ans; } ll pow2(ll a,ll b) { ll ans=1; while(b) { if(b&1) { ans*=a; ans%=mod2; b--; } b>>=1; a*=a; a%=mod2; } return ans; } int main() { ll aa,bb,an,bn,n; while(scanf("%lld%lld%lld",&aa,&bb,&n)!=EOF) { matrix a= {1,1,1,0}; matrix ans; ans=pow(a,n); bn=ans.data[0][1]; an=ans.data[1][1]; //cout<<"a: "<<an<<" b: "<<bn<<endl; ll ans2=((pow2(aa,an)%mod2)*(pow2(bb,bn)%mod2))%mod2; printf("%lld\n",ans2); } return 0; }
标签:
原文地址:http://www.cnblogs.com/Ritchie/p/5568047.html