杭电ACM1005 Number SequenceA 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). InputThe input consists of multiple test cases. Each test c
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/31 11:12:11
![杭电ACM1005 Number SequenceA 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). InputThe input consists of multiple test cases. Each test c](/uploads/image/z/6809734-46-4.jpg?t=%E6%9D%AD%E7%94%B5ACM1005+Number+SequenceA+number+sequence+is+defined+as+follows%3Af%281%29+%3D+1%2C+f%282%29+%3D+1%2C+f%28n%29+%3D+%28A+%2A+f%28n+-+1%29+%2B+B+%2A+f%28n+-+2%29%29+mod+7.Given+A%2C+B%2C+and+n%2C+you+are+to+calculate+the+value+of+f%28n%29.+InputThe+input+consists+of+multiple+test+cases.+Each+test+c)
杭电ACM1005 Number SequenceA 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). InputThe input consists of multiple test cases. Each test c
杭电ACM1005 Number Sequence
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).
Input
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1
杭电ACM1005 Number SequenceA 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). InputThe input consists of multiple test cases. Each test c
/*
1 1 3
2
1 2 10
5
0 0 0
Press any key to continue
*/
#include<stdio.h>
int main(void) {
\x09int a1 = 1,a2 = 1,an;
\x09int A,B,n,i;
\x09while(1) {
\x09\x09scanf("%d%d%d",&A,&B,&n);
\x09\x09if(A == 0 && B == 0 && n == 0) break;
\x09\x09a1 = 1;
\x09\x09a2 = 1;
\x09\x09for(i = 3; i <= n; ++i) {
\x09\x09\x09an = (A * a2 + B * a1) % 7;
\x09\x09\x09a1 = a2;
\x09\x09\x09a2 = an;
\x09\x09}
\x09\x09printf("%d\n",an);
\x09}
\x09return 0;
}