codeforces 450 B Jzzhu and Sequences
2015-04-23 13:08
330 查看
题意:给出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
View Code
因为 可以求出通项公式: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
#include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set> #include<queue> #include<algorithm> using namespace std; typedef long long LL; const int INF = (1<<30)-1; const int mod=1000000007; const int maxn=100005; LL a[15]; int main(){ LL x,y,n; cin>>x>>y; cin>>n; a[1]=(x+mod)%mod; a[2]=(y+mod)%mod; a[3]=(y-x+2*mod)%mod; a[4]=(-x+mod)%mod; a[5]=(-y+mod)%mod; a[0]=(-y+x+2*mod)%mod; cout<<a[n%6]<<"\n"; return 0; }
View Code
相关文章推荐
- Codeforces 450 B. Jzzhu and Sequences
- codeforces - 450 - B - Jzzhu and Sequences 【简单的矩阵快速幂】
- Codeforces 450 B. Jzzhu and Sequences
- CodeForces 450-B. Jzzhu and Sequences
- codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)
- codeforces 450-B Jzzhu and Sequences 矩阵快速幂
- Jzzhu and Sequences CodeForces - 450B (矩阵快速幂)
- Codeforces Div. 2 #257-B. Jzzhu and Sequences
- 【矩阵快速幂 】Codeforces 450B - Jzzhu and Sequences (公式转化)
- CodeForces 450-A. Jzzhu and Children
- CF 450 B Jzzhu and Sequences(矩阵快速幂)
- codeforces-DIV2-B- Jzzhu and Sequences
- Codeforces 450 C. Jzzhu and Chocolate
- Codeforces 450 C. Jzzhu and Chocolate
- Codeforces 450 C. Jzzhu and Chocolate
- Codeforces 450 C. Jzzhu and Chocolate
- codeforces 257div2 B. Jzzhu and Sequences(细节决定一切)
- Codeforces_450B_Jzzhu and Sequences(循环节or矩阵快速幂)
- CodeForces 450B-Jzzhu and Sequences
- Codeforces 450B-Jzzhu and Sequences (矩阵快速幂)