Jzzhu has invented a kind of sequences, they meet the following property:

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).
题意很简单。
题解:f[0]=x,f[1]=y,f[2]=y-x,f[3]=-x,f[4]=-y,f[5]=x-y。然后开始重复了,节点为6.这里求余1e9+7有个问题是负号,即是1e9+7加上这个数。有可能还是有点问题,懒得看了。
#include <bits/stdc++.h>
using namespace std;
const int M=1e9+7;
__int64 f[10],n;
__int64 mod(__int64 x)
{
if (x>=0) return x % M;
else return M+x;
}
int main()
{
scanf("%I64d%I64d",&f[0],&f[1]);
//f[0]=mod(f[0]);
//f[1]=mod(f[1]);
f[2]=mod(f[1]-f[0]);
f[3]=mod(0-f[0]);
f[4]=mod(0-f[1]);
f[5]=mod(f[0]-f[1]);
scanf("%I64d",&n);
printf("%d\n",mod(f[(n-1) % 6]));
return 0;
}