AI智能
改变未来

Jzzhu and Sequences(找规律)

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 ansans[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;elsecout << (result % MOD + MOD) % MOD << endl;return 0;}
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » Jzzhu and Sequences(找规律)