标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define N 101
int f[N];
int main()
{
int A, B, n;
f[1] = 1;
f[2] = 1;
while (scanf("%d%d%d", &A, &B, &n) == 3 && n){
int begin, end;
bool flag = false;
for (int i = 3; i <= n && !flag; i++){
f[i] = (A * f[i - 1] + B * f[i - 2]) % 7;
for (int j = 2; j <= i - 1; j++){
if (f[i] == f[j] && f[i - 1] == f[j - 1]){
begin = j, end = i;
flag = true;
break;
}
}
}
if (flag)
printf("%d\n", f[begin + (n - end) % (end - begin)]);
else
printf("%d\n", f[n]);
}
//system("pause");
return 0;
}
标签:
原文地址:http://www.cnblogs.com/Lynnray/p/5372323.html