![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int rec[60]; 5 6 int main() 7 { 8 int a, b, n; 9 rec[0] = rec[1] = rec[2] = 1; 10 while( scanf( "%d %d %d", &a, &b, &n ), a | b | n ) 11 { 12 int beg, end, flag = 0; 13 for( int i = 3; i <= n && !flag; ++i ) 14 { 15 rec[i] = ( a * rec[i-1] + b * rec[i-2] ) % 7; 16 for( int j = 2; j <= i - 1; ++j ) 17 { 18 if( rec[i] == rec[j] && rec[i-1] == rec[j-1] ) 19 { 20 beg = j, end = i; 21 flag = 1; 22 break; 23 } 24 } 25 } 26 if( flag ) 27 { 28 printf( "%d\n", rec[beg+(n-end)%(end-beg)] ); 29 } 30 else 31 printf( "%d\n", rec[n] ); 32 } 33 return 0; 34 }