Question Link
Wa many times, because of a small error,
# Include <cstdio>
Using namespace STD;
Int f [1000001];
Int main ()
{
Int A, B, n, I, time;
While (scanf ("% d", & A, & B, & N) & (A | B | N ))
{
F [1] = 1;
F [2] = 1;
For (I = 3; I <= 50; I ++) // note that the cycle is 49, and each result is MoD
7, so each result can have a maximum of 7 results. One result is related to the first two results. Therefore, different results can have a maximum of 7*7 = 49 results.
{
F [I] = (A * f [I-1] + B * f [I-2]) % 7;
If (F [I] = 1 & F [I-1] = 1)
{
Break;
}
}
Time = I-2; // if there is re in the IF statement, the reason is
For example, if both A and B are multiples of 7 and all values from FN [2] to 0, the IF statement will not be executed until the end of the for loop, then execute printf ("% d \ n", FN [N]). Therefore, it is important to consider carefully.
N % = time;
If (n = 0) n = time;
Printf ("% d \ n", F [N]);
}
Return 0;
}