杭电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
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/13 23:05:58
杭电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;
}