codeforces 450B Jzzhu and Sequences

题目链接:http://codeforces.com/contest/450/problem/B
解题思路:找循环节。注意当f[i]是负数的时候一定要把他加上mod直到>0为止;
e:- 3 % 4 == 1;

#include <iostream>

using namespace std;
const int mod=1e9+7;
typedef long long LL;
LL f[10];
int main()
{
    LL x,y,k;
    while(cin>>x>>y>>k)
    {
        x = (x + mod) % mod;
        y = (y + mod) % mod;
        f[0] = x;
        f[1] = y;
        f[2] = (y - x + mod) % mod;
        f[3] = (-x + mod) % mod;
        f[4] = (-y + mod) % mod;
        f[5] = (x - y +mod) % mod;
        cout<<f[(k-1) % 6]<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/mfmdaoyou/p/7258258.html