#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std; const int M = 1e9+; struct Matrix {
long long a[][];
Matrix() {
memset(a, , sizeof(a));
}
Matrix operator * (const Matrix y) {
Matrix ans;
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++)
for(int k = ; k <= ; k++)
ans.a[i][j] += a[i][k]*y.a[k][j];
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++)
ans.a[i][j] %= M;
return ans;
}
void operator = (const Matrix b) {
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++)
a[i][j] = b.a[i][j];
}
}; int solve(long long x) {
Matrix ans, trs;
ans.a[][] = ans.a[][] = ;
trs.a[][] = trs.a[][] = trs.a[][] = ;
while(x) {
if(x&)
ans = ans*trs;
trs = trs*trs;
x >>= ;
}
return ans.a[][];
} int main() {
int n;
scanf("%d", &n);
cout << solve(n-) << endl;
return ;
}

POJ 3070

矩阵快速幂 求斐波那契第N项的更多相关文章

  1. codeforce 227E 矩阵快速幂求斐波那契+N个连续数求最大公约数+斐波那契数列的性质

    E. Anniversary time limit per test2 seconds memory limit per test256 megabytes inputstandard input o ...

  2. UVA - 10689 Yet another Number Sequence (矩阵快速幂求斐波那契)

    题意:已知f(0) = a,f(1) = b,f(n) = f(n − 1) + f(n − 2), n > 1,求f(n)的后m位数. 分析:n最大为109,矩阵快速幂求解,复杂度log2(1 ...

  3. poj3070矩阵快速幂求斐波那契数列

      Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13172   Accepted: 9368 Desc ...

  4. 51 Nod 1242 矩阵快速幂求斐波那契数列

    #include<bits/stdc++.h> #define mod 1000000009 using namespace std; typedef long long ll; type ...

  5. 矩阵快速幂--51nod-1242斐波那契数列的第N项

    斐波那契额数列的第N项 斐波那契数列的定义如下: F(0) = 0 F(1) = 1 F(n) = F(n - 1) + F(n - 2) (n >= 2) (1, 1, 2, 3, 5, 8, ...

  6. codeforces gym #101161G - Binary Strings(矩阵快速幂,前缀斐波那契)

    题目链接: http://codeforces.com/gym/101161/attachments 题意: $T$组数据 每组数据包含$L,R,K$ 计算$\sum_{k|n}^{}F(n)$ 定义 ...

  7. python 快速幂求斐波那契数列

    先占坑 后面再写详细的 import numpy as np def pow(n): a = np.array([[1,0],[0,1]]) b = np.array([[1,1],[1,0]]) n ...

  8. POJ 3070 - 快速矩阵幂求斐波纳契数列

    这题并不复杂. 设$A=\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}$ 由题中公式: $\begin{pmatrix}f(n+1) & ...

  9. POJ-3070Fibonacci(矩阵快速幂求Fibonacci数列) uva 10689 Yet another Number Sequence【矩阵快速幂】

    典型的两道矩阵快速幂求斐波那契数列 POJ 那是 默认a=0,b=1 UVA 一般情况是 斐波那契f(n)=(n-1)次幂情况下的(ans.m[0][0] * b + ans.m[0][1] * a) ...

随机推荐

  1. sock( ) bind( ) connect( )

    Linux下的socket()函数 调用头文件<sys/socket.h>中的socket函数 int socket(int af, int type, int protocol); 1) ...

  2. Android NDK下载

    http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin https://dl.google.com/android/rep ...

  3. java基础--继承、实现、依赖、关联、聚合、组合的联系与区别

    继承 指的是一个类或者接口继承另一个类或者接口,而且可以增加自己的新功能. 实现 指的是一个class类实现interface接口. 依赖 简单说,就是一个类中的方法用到了另一个类,一般依赖关系在ja ...

  4. Spring mvc注解说明

    编号 注解 说明 位置 备注 1 @Controller 将类变成Spring Bean 类 现阶段 @Controller . @Service 以及 @Repository 和 @Componen ...

  5. 红帽虚拟化RHEV3.2创建虚拟机(图文Step by Step)

    目录 目录 前言 Install RHEV 创建Data CenterClusterHost 创建存储 创建虚拟机 前言 RHEV3.2的Web管理界面有了很大的改进,更加的简单和便捷,还可以使用中文 ...

  6. 阶段3 1.Mybatis_09.Mybatis的多表操作_8 mybatis多对多操作-查询角色获取角色下所属用户信息

    一个角色对应多个用户 生成getter和setter 查看两个表的数据 中间表定义了谁有角色,谁没有角色 根据中间表的关系,最终查询出来的列表的数据样子.这需要两个左外链接才能实现功能. 第一个左外链 ...

  7. 正则表达式——推荐使用 Unicode 编码

      常见的正则表达式的文档都是关于英文(ASCII字符)的,英文开发者通常也只需要处理ASCII字符,不需要处理中文这类多字符的字符.不过,依照李处ASCII字符的方式处理中文字符,就有可能出错.   ...

  8. Linux系统常用命令之top

    top - 06:58:37 up 7 days, 23:36, 2 users, load average: 0.00, 0.01, 0.05Tasks: 716 total, 1 running, ...

  9. nodejs 对接微信 express 对接微信

    安装引用 npm install express npm install body-parser npm install express-xml-bodyparser npm install axio ...

  10. PostgreSQL索引思考

    当在看Monetdb列存行只支持IMPRINTS和ORDERED这两种索引,且只支持定长数值类型时,就在思考,对于列存,还有必要建索引吗?在PostgreSQL的索引就要灵活很多,我对常用列建合理的索 ...