本文主要是介绍Codeforces 450B - Jzzhu and Sequences,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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).
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 fn modulo 1000000007 (109 + 7).
Examples
Input
2 3 3
Output
1
Input
0 -1 2
Output
1000000006
// 矩阵快速幂题,
//但是,有个简单方法,就是
// 找规律, 每 6 个为依次循环
// 转化成暴力求解了#include<iostream>
using namespace std;
long long ans[6];
int main(void){long long int x,y; long long int n;long long mod = 1000000007;while( scanf("%lld%lld%lld",&x,&y,&n)!=EOF){ans[0] = (x%mod +mod)%mod;ans[1] = (y%mod +mod)%mod;for( int i=2;i<=5;i++){ ans[i] = ( ans[i-1] - ans[i-2] ) % mod; if( ans[i] < 0 )ans[i] +=mod;} printf("%lld\n",ans[ (n-1)%6 ]);} return 0;
}
这篇关于Codeforces 450B - Jzzhu and Sequences的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!