Jzzhu has invented a kind of sequences, they meet the following property:
![](http://codeforces.com/predownloaded/55/53/5553125ed3b40d54293e6c3b9dac2692d9f2a964.png)
You are given x and y, please calculate fn modulo 1000000007 (109 + 7).
The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output a single integer representing fn modulo 1000000007 (109 + 7).
2 3 3
1
0 -1 2
1000000006
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6).
题意:求fn
题解:规律题,注意int会爆
代码:
#include <iostream>
using namespace std;
long long f1,f2;
long long a[10];
long long b[10];
int main()
{
scanf("%lld %lld",&f1,&f2);
long long n;
scanf("%lld",&n);
b[0] = (f1+1000000007)%1000000007;
b[1] = (f2+1000000007)%1000000007;
b[2] = (f2-f1+1000000007)%1000000007;
b[3] = (-f1+1000000007)%1000000007;
b[4] = (-f2+1000000007)%1000000007;
b[5] = (-f2+f1+1000000007)%1000000007;
printf("%lld\n",(b[(n-1)%6]+1000000007)%1000000007);
}