【51NOD1242】斐波那契数列的第N项(矩阵快速幂)
来源:互联网 发布:自动变速箱编程 编辑:程序博客网 时间:2024/06/01 01:33
记录一个菜逼的成长。。
题目链接
ps:只是记下模板。
这题有个坑,用多组输入就TLE.
//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <cstdlib>#include <vector>#include <set>#include <map>#include <queue>#include <stack>#include <list>#include <deque>#include <cctype>#include <bitset>#include <cmath>#include <cassert>using namespace std;#define ALL(v) (v).begin(),(v).end()#define cl(a,b) memset(a,b,sizeof(a))#define bp __builtin_popcount#define pb push_back#define mp make_pair#define fin freopen("D://in.txt","r",stdin)#define fout freopen("D://out.txt","w",stdout)#define lson t<<1,l,mid#define rson t<<1|1,mid+1,r#define seglen (node[t].r-node[t].l+1)#define pi 3.1415926#define exp 2.718281828459#define lowbit(x) (x)&(-x)typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> PII;typedef pair<LL,LL> PLL;typedef vector<PII> VPII;const int INF = 0x3f3f3f3f;//const int MOD = 1e9 + 7;template <typename T>inline void read(T &x){ T ans=0; char last=' ',ch=getchar(); while(ch<'0' || ch>'9')last=ch,ch=getchar(); while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar(); if(last=='-')ans=-ans; x = ans;}const int MOD = 1000000009;typedef vector<LL> vec;typedef vector<vec> mat;LL n;mat mul(mat &A,mat &B){ mat C(A.size(),vec(B[0].size())); for( int i = 0; i < A.size(); i++ ){ for( int k = 0; k < B.size();k++ ){ for( int j = 0; j < B[0].size();j++ ){ C[i][j] = (C[i][j] + A[i][k] * B[k][j]); C[i][j] %= MOD; } } } return C;}mat pow(mat A,LL n){ mat B(A.size(),vec(A.size())); for( int i = 0; i < A.size(); i++ ){ B[i][i] = 1; } while(n > 0){ if(n & 1)B = mul(B,A); A = mul(A,A); n >>= 1; } return B;}void solve(){ mat A(2,vec(2)); A[0][0] = A[0][1] = A[1][0] = 1; A[1][1] = 0; A = pow(A,n); printf("%lld\n",A[1][0]);}int main(){ scanf("%lld",&n); solve(); return 0;}
0 0
- 【51NOD1242】斐波那契数列的第N项(矩阵快速幂)
- 51nod1242 斐波那契数列的第N项(矩阵)
- 矩阵乘法 与 矩阵快速幂详解 以51NOD1242 斐波那契数列的第N项为例
- 51nod1242 斐波那契数列的第N项
- 51nod1242 斐波那契数列的第N项
- 51nod 1242 斐波那契数列的第N项(矩阵快速幂)
- 51nod 1242 斐波那契数列的第N项【矩阵快速幂】
- 51nod 1242 斐波那契数列的第N项 (矩阵快速幂)
- 【51Nod】1242 - 斐波那契数列的第N项(矩阵快速幂)
- 51nod 1242 斐波那契数列的第N项(矩阵快速幂)
- 51Nod-斐波那契数列的第N项(矩阵快速幂)
- [51NOD]-1242 斐波那契数列的第N项 [矩阵快速幂]
- 51 nod 1242 斐波那契数列的第N项 矩阵快速幂
- 51Nod 1242 斐波那契数列的第N项(矩阵快速幂)
- 矩阵快速幂1242斐波那契数列的第N项
- 斐波那契数列的第N项 矩阵快速幂
- 1242 斐波那契数列的第N项(矩阵快速幂)
- 斐波那契数列的第N项(矩阵快速幂模板)
- 百度语音合成(TTS) 在Android的使用方法
- AC自动机算法及模板
- Java中的Static class
- 一个神奇的文件Dockerfile
- 浅谈Java内部类的四个应用场景
- 【51NOD1242】斐波那契数列的第N项(矩阵快速幂)
- java内省详解
- maven(4)------maven核心pom.xml文件常用元素分析
- 神经网络训练之交叉验证
- 关于SQL语句的排序问题
- C# 保存Excel文件 ( 打开Excel文件格式与扩展名指定格式不一致)
- PHP-FPM自启动脚本编写与详细操作说明
- 确定两串乱序同构
- Linux下FTP服务器默认目录的更改方法