标签:
#include<stdio.h>
int main(){
int c[51]={1,1};
int time;
int a,b,n;
int i;
while(scanf("%d %d %d",&a,&b,&n)!=EOF){
if(a==0&&b==0&&n==0)
break;
a%=7;
b%=7;
c[2]=(a*c[1]+b*c[0])%7;
c[3]=(a*c[2]+b*c[1])%7;
for(i=4;i<51;i++){
c[i]=(a*c[i-1]+b*c[i-2])%7;
if(c[i]==c[2]&&c[i+1]==c[3])
break;
}
time=i-2;
if(n>2)
printf("%d\n",c[(n-2)%time+1]);
else
printf("%d\n",c[n-1]);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/ganeveryday/p/4378826.html