您的位置:首页 > 产品设计 > UI/UE

Jzzhu and Sequences(找规律)

2020-07-16 06:07 1051 查看

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

You are given x and y, please calculate f n modulo 1000000007 (109 + 7).

Input
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
Output a single integer representing f n modulo 1000000007 (109 + 7).

Examples
Input

2 3
3

Output
1

Input
0 -1
2

Output
1000000006

找规律的题目!
很神奇!

#include <iostream>

using namespace std;

const int MOD = 1000000007;
const int N = 6;

int ans[N];

int main()
{
int x, y, n;

cin >> x >> y >> n;

// Init ans
ans[0] = x - y;
ans[1] = x;
ans[2] = y;
ans[3] = y - x;
ans[4] = -x;
ans[5] = - y;

int result = ans[n % N];
if(result >= 0)
cout << result % MOD << endl;
else
cout << (result % MOD + MOD) % MOD << endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: