#include <cstdio> int f(int a,int b,int n) { int i,nn,n1,n2; if(n==1||n==2)return 1; a%=7; b%=7; n%=49; n1=n2=1; for(i=2; i<n; i++) { nn=(a*n2+b*n1)%7; n1=n2; n2=nn; } return nn; } int main(void) { int a,b,n; while(scanf("%d%d%d",&a,&b,&n),a) printf("%d\n",f(a,b,n)); return 0; }
时间: 2024-11-30 06:39:54