0
点赞
收藏
分享

微信扫一扫

B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)

原题链接: ​​https://codeforces.com/problemset/problem/450/B​​

B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_取模
测试样例

Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006

Note

In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 =  - 1;  - 1 modulo B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_c代码_02 equals B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_取模_03.

题意: 给出一个序列如下:
B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_c代码_04

需要你求出B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_取模_05 mod B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_#define_06的值。

解题思路: 这道题我们肯定不是无脑递归推下去的,这肯定不现实,那么我们该如何做呢?根据给定信息入手,既然B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_c代码_07。那么B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_#define_08.又因为B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_c代码_09.这两个式子相加我们自然可以得到B. Jzzhu and Sequences(思维)Codeforces Round #257 (Div. 2)_取模_10 故我们可以得到这个序列周期为6,则我们把前六个数求出来即可。注意,我们负数取模的规则为先加模再取模。

AC代码

/*

*
*/
#include<bits/stdc++.h>//POJ不支持

#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)

using namespace std;

const int inf=0x3f3f3f3f;//无穷大。
const int maxn=1e5;//限定值。
typedef long long ll;
const ll mod=1000000007;
ll a[6];
int n;
int main(){
while(cin>>a[0]>>a[1]){
cin>>n;
rep(i,2,5){
a[i]=(a[i-1]-a[i-2])%mod;
}
cout<<(a[(n-1)%6]+mod)%mod<<endl;
}
return 0;
}


举报

相关推荐

0 条评论