Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
来源:互联网 发布:mac spss24 编辑:程序博客网 时间:2024/05/18 21:06
题目链接:Jzzhu and Sequences
题目大意:给你一个递推式,求f(n)%1e+7
题目思路:先要把给的递推式转化一下,然后求余的时候记得+MOD再求余就好了
#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <vector>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const ll maxn = 2;const ll MOD = 1e9+7;#define mod(x) ((x)%MOD)struct mat{ ll m[maxn][maxn];}unit;mat operator *(mat a,mat b){ mat ret; ll x; for(ll i = 0;i < maxn;i++){ for(ll j = 0;j < maxn;j++){ x = 0; for(ll k = 0;k < maxn;k++) x += mod((ll)a.m[i][k]*b.m[k][j]); ret.m[i][j] = mod(x); } } return ret;}void init_unit(){ for(ll i = 0;i < maxn;i++) unit.m[i][i] = 1; return ;}mat pow_mat(mat a,ll n){ mat ret = unit; while(n){ if(n&1) ret = ret*a; a = a*a; n >>= 1; } return ret;}int main(){ ll n,x,y; init_unit(); while(~scanf("%lld%lld%lld",&x,&y,&n)){ if(n == 1ll) printf("%lld\n",(x+MOD)%MOD); else if(n == 2ll) printf("%lld\n",(y+MOD)%MOD); else{ mat a,b; b.m[0][0] = 1,b.m[0][1] = 1; b.m[1][0] = -1,b.m[1][1] = 0; a.m[0][0] = y,a.m[0][1] = x; b = pow_mat(b,n-2); a = a*b; printf("%lld\n",(a.m[0][0]+MOD)%MOD); } } return 0;}
阅读全文
0 0
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2)1B Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B Jzzhu and Sequences
- Codeforces Round #257 (Div. 2)B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) 450B - Jzzhu and Sequences(循环节或矩阵快速幂)
- Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵快速幂)
- Codeforces #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Div. 2 #257-B. Jzzhu and Sequences
- Codeforces#257 (Div. 2) B. Jzzhu and Sequences (数学
- Codeforces Round #257 (Div. 2/B)/Codeforces450B_Jzzhu and Sequences
- Excel合并工作表的神器—Power Query
- 面向对象--构造函数
- linux线程池
- iOS获取设备型号和App版本号等信息(OC+Swift3.0)
- Memcached expire 设置错误引起的set(key,exp,value)为true而get(key)为null的问题
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- sql 查询按照分组将多条记录转换成单条记录的group_contact()函数
- ffmpeg中的x264编码选项,对应关系
- Unity Shader学习笔记:入门简述
- EasyUI使用代码
- POJ 2774Long Long Message(后缀数组入门题)
- SpringMVC--配置FastJSON为JSON处理器
- STRHH
- 换个名字就OK?