Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 65536/32768 K
(Java/Others)
Total Submission(s): 92129 Accepted
Submission(s): 21967
#include<iostream> #include<string> using namespace std; int a[21]; int A=1, B=1, n; int f(int x) { if (x == 1 || x == 2)return 1; if (a[x])return a[x]; else return a[x] = (A*f(x - 1) + B*f(x - 2)) % 7; } int main() { while (1){ cin >> A >> B >> n; if (A == 0 && B == 0 && n == 0)break; memset(a, 0, sizeof(a)); f(20); a[0] = a[16]; a[1] = a[17]; a[2] = a[18]; if (n == 1 || n == 2){ cout << "1\n"; } else{ cout << a[n % 16] << endl; } } system("pause"); return 0; }
规律题,只要把前几十个打出来看一下就知道了。水题~
原文:http://www.cnblogs.com/littlehoom/p/3549276.html