一个找规律的题目,找出其中的规律就OK了。
n所给范围这么大,应该首先想到题目是有规律性的。
要注意n%t==0的情况。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
int s[60];
int main()
{
int A,B,n;
while(scanf("%d%d%d",&A,&B,&n)!=EOF&&A&&B&&n)
{
int i,t;
s[1]=1;
s[2]=1;
for(i=3;i<50;i++)
{
s[i]=(A*s[i-1]+B*s[i-2])%7;
if(s[i]==1&&s[i-1]==1)
break;
}
t=i-2;
n=n%t;
if(n==0)
n=t;
printf("%d\n",s[n]);
}
return 0;
}