⇤ ← 于2006-03-11 17:02:19修订的的版本1
738
备注:
|
1279
|
删除的内容标记成这样。 | 加入的内容标记成这样。 |
行号 32: | 行号 32: |
#include<iostream>//AC #include<vector> using namespace std; int main() { int A,B; int n; int i,t; t=0; vector<int> a; cin>>A>>B>>n; while(A!=0||B!=0||n!=0) { A=A%7; B=B%7; a.push_back(1); a.push_back(1); for(i=2;i<n;++i) { a.push_back((A*a[i-1]+B*a[i-2])%7); if(a[i]==a[3]&&a[i-1]==a[2]&&i!=3) { t=i-3; break; } } if(t!=0) cout<<a[((n-3)%t)+2]<<endl; else cout<<a[n-1]<<endl; a.clear(); t=0; cin>>A>>B>>n; } return 0; } |
Number Sequence
Time limit: 1 Seconds
Memory limit: 32768K
A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n).
1. Input
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.
2. Output
For each test case, print the value of f(n) on a single line.
3. Sample Input
{{{1 1 3 1 2 10 0 0 0 }}}