依次求值,代码如下:
//杭电OJ 1005 张艺川 2018/1/27
#include<iostream>
using namespace std;
int main(){
int A, B, n;
while (cin >> A >> B >> n && A != 0){//由题目给出范围简化判定条件
int *number = new int[n];
number[0] = 1;
number[1] = 1;
for (int i = 2; i < n; i++){
number[i] = A*number[i - 1] + B*number[i - 2];
number[i] %= 7;
}
cout << number[n - 1] << endl;
delete[]number;
}
return 0;