codeforces 450 B Jzzhu and Sequences

题意:给出f1=x,f2=y,f(i)=f(i-1)+f(i+1),求f(n)模上10e9+7

因为 可以求出通项公式:f(i)=f(i-1)-f(i-2)

然后

f1=x;

f2=y;

f3=y-x;

f4=-x;

f5=-y;

f6=-y+x;

f7=x; 发现是以6为循环的

还有注意下余数为正,就每次加上一个mod再模上mod

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath> 
 5 #include<stack>
 6 #include<vector>
 7 #include<map> 
 8 #include<set>
 9 #include<queue> 
10 #include<algorithm>  
11 using namespace std;
12 
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=100005;
17 
18 LL a[15];
19 
20 int main(){
21     LL x,y,n;
22     cin>>x>>y;
23     cin>>n;
24     a[1]=(x+mod)%mod;
25     a[2]=(y+mod)%mod;
26     a[3]=(y-x+2*mod)%mod;
27     a[4]=(-x+mod)%mod;
28     a[5]=(-y+mod)%mod;
29     a[0]=(-y+x+2*mod)%mod;
30     cout<<a[n%6]<<"\n";
31     return 0;
32 }
View Code

 

posted @ 2015-04-23 13:08  sequenceaa  阅读(197)  评论(0编辑  收藏  举报