51nod1242【矩阵快速幂】
来源:互联网 发布:python macd函数 编辑:程序博客网 时间:2024/05/27 20:50
基础题。。
wa在n的范围需要用long long
= =、长个记性
#include<bits/stdc++.h>using namespace std;typedef long long LL;const LL mod=1e9+9;struct asd{ LL a[2][2];};asd mul(asd x,asd y){ asd ans; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { ans.a[i][j]=0; for(int k=0;k<2;k++) { ans.a[i][j]=ans.a[i][j]+(x.a[i][k]*y.a[k][j])%mod; ans.a[i][j]%=mod; } } } return ans;}asd quickmul(LL g,asd x){ asd ans; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { if(i==j) ans.a[i][j]=1; else ans.a[i][j]=0; } } while(g) { if(g&1) ans=mul(ans,x); x=mul(x,x); g>>=1; } return ans;}int main(){ LL n; scanf("%lld",&n); if(n==0||n==1) { printf("%lld\n",n); return 0; } asd x,ans; x.a[0][0]=1;x.a[0][1]=1; x.a[1][0]=1;x.a[1][1]=0; ans=quickmul(n-1,x); printf("%lld\n",ans.a[0][0]); return 0;}
0 0
- 51nod1242【矩阵快速幂】
- 【51NOD1242】斐波那契数列的第N项(矩阵快速幂)
- 矩阵乘法 与 矩阵快速幂详解 以51NOD1242 斐波那契数列的第N项为例
- 51nod1242 斐波那契数列的第N项(矩阵)
- 快速矩阵快速幂
- 51nod1126【矩阵快速幂】
- 51nod1126【矩阵快速幂】
- 51nod1113【矩阵快速幂】
- 矩阵快速幂 51nod
- 51 Nod1113 矩阵快速幂
- 转移矩阵+矩阵快速幂
- 矩阵乘法 矩阵快速幂
- 构造矩阵+矩阵快速幂
- 矩阵快速幂,矩阵加法,矩阵乘法
- 快速幂||矩阵快速幂
- 快速幂&矩阵快速幂
- 快速幂,矩阵快速幂
- 快速幂 矩阵快速幂
- 25条提高iOS App性能的技巧和诀窍----
- Cannot negotiate authentication mechanism
- 前端CSS规范大全(转载)
- poj 2586
- webservice之WSDL资料详解
- 51nod1242【矩阵快速幂】
- 商品详情的图片放大效果
- 仿知乎日报第四篇:MainActivity使用SlidingMenu开源项目完成基本的结构
- CSS 属性选择器
- 【MUI】HBuilder class="mui-switch"开关监听
- Qt之生成pdf
- 单例模式
- iOS_Pass iOS hotfix 热更新 JSPatch 个人服务搭建方案
- linux下怎么安装JAVA?