51nod 1358 浮波那契
来源:互联网 发布:java简单记事本源代码 编辑:程序博客网 时间:2024/04/29 19:11
构造新数列f(n)=f(n-10)+f(n-34),n>40,f(n)=1,n<=40,则FB(n)=f(10n)#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define LL long longconst int p=1e9+7;struct Matrix{ LL a[35][35]; Matrix(){memset(a,0,sizeof a);} Matrix operator*(const Matrix &m) { Matrix res; for(int i=0;i<35;i++) { for(int j=0;j<35;j++) { for(int k=0;k<35;k++) { res.a[i][j]+=a[i][k]*m.a[k][j]%p; } res.a[i][j]%=p; } } return res; }}ans,base;Matrix pow(Matrix base,LL n){ Matrix res; for(int i=0;i<35;i++) res.a[i][i]=1; while(n) { if(n&1) res=res*base; base=base*base; n>>=1; } return res;}int main(){ LL n; while(~scanf("%lld",&n)) { if(n<=4) puts("1"); else { for(int i=0;i<35;i++) ans.a[0][i]=1; base.a[9][0]=1,base.a[33][0]=1; for(int i=1;i<35;i++) base.a[i-1][i]=1; ans=ans*pow(base,10*n-40); printf("%lld\n",(ans.a[0][0]+p)%p); } } return 0;}
0 0
- 51nod 1358 浮波那契
- 51nod 1358 浮波那契
- 51nod-1358:浮波那契
- 51nod 1358 浮波那契
- 51nod 1358:浮波那契 构造矩阵
- 51Nod 1358 浮波那契 (矩阵快速幂)
- 51Nod-1358-浮波那契
- 51nod-1358-浮波那契(构造矩阵)
- 51nod 1358 浮波那契 (类斐波那契数列+矩阵快速幂+构造矩阵)
- 51nod 1358 浮波那契【思维+矩阵快速幂】好题!
- 51Nod 1358 浮波那契 (矩阵快速幂 构造矩阵)
- 51nod 1070 斐波那契博弈
- 51nod 1628 非波那契树 (倍增)
- 51Nod-1350-斐波那契表示
- 51nod 1350 斐波那契表示
- 51nod-斐波那契表示(找规律)
- 51nod-1350:斐波那契表示
- 51nod-1350 斐波那契表示(规律)
- PAT(B) - 1059. C语言竞赛(20)
- 手机端中有的图片可以显示有的不显示的问题
- PAT(B) - 1057. 数零壹(20)
- AsyncTask 异步任务解析
- 2-36进制数的任意转换
- 51nod 1358 浮波那契
- Android 中的adapter和作用以及常见的adapter
- 三门问题
- mysql远程连接时出现的ERROR
- c#发送get请求
- Chromium扩展(Extension)通信机制分析
- L-BFGS算法
- EasyPlayer Android音频解码库(第一部分,ffmpeg-android的编译)
- Android基础常用日期操作工具类