1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
using namespace std; int N=7; void Matrix(int (&a)[2][2],int b[2][2]){ int tmp[2][2]={0}; for(int i=0;i<2;++i) for(int j=0;j<2;++j) for(int k=0;k<2;++k) tmp[i][j]=(tmp[i][j]+a[i][k]*b[k][j])%N; for(int i=0;i<2;++i){ for(int j=0;j<2;++j){ a[i][j]=tmp[i][j]; } } } int main(){ int a,b,n; while(scanf("%d%d%d",&a,&b,&n)){ if(a==0&&b==0&&n==0)break; if(n==1){ cout<<1<<endl; continue; } int temp[2][2]={a,b,0,0},cot[2][2]={1,0,0,1}, x[2] = {1, 1}; n-=2; while(n){ if(n&1)Matrix(cot,temp); Matrix(temp,temp); n/=2; } int ans=0; for(int i=0;i<2;i++) ans=(ans+x[i]*cot[0][i])%N; cout<<ans<<endl; } }
|
近期评论