杭电ACM 1005题 为什么有49种组合,求解释,该怎么处理

杭电ACM 1005题 为什么有49种组合,求解释number sequence is defined as follows:f(1) 1, f(2) 1, f(n

杭电ACM 1005题 为什么有49种组合,求解释
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).



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.



Output
For each test case, print the value of f(n) on a single line.



Sample Input
1 1 3
1 2 10
0 0 0


Sample Output
2
5


题目是这样的,答案是
#include <iostream>
using namespace std;
int main()
{
  int A,B,i;
  long n,number[50];
  number[1]=number[2]=1;
  while(cin>>A>>B>>n)
  {
  if(A==0&&B==0&&n==0)break;
  else
  {
  for(i=3;i<=48;i++)
  number[iH]=(A*number[i-1]+B*number[i-2])%7;
  cout<<number[nH]<<endl;
  }
  }
  return 0;
}

为什么有7*7=49是一个循环?

[解决办法]
每一项的取值范围是0~6,共7个
而每一项由前2项的值决定
那不就是7*7=49个组合,最多经过49个就一个循环
[解决办法]
是个数学题目 多想想 就好了
[解决办法]
把值写出来,多写一点,就能找到规律吧
[解决办法]
f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7 所以f(n)的取值范围为0-6,有7中情况,三个零信号输入端,本次测试的情况下是不被处理,当f(n-1)=0且f(n-2)=0时 f(n)肯定是0 ,f(n+1)...这些都肯定是0, f(n - 1)与 f(n - 2)的组合有7*7种,大于49次操作肯定有重复的