#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. linux grep 正则

    grep : 显示匹配行 -v: 反显示 -e 使用扩展正则表达式 黑色字体表明是原生正则表达式 红色字体表明是扩张正则表达式 1.匹配操作符 \: 转义字符串(正则使用扩展字符操作  没有使用-e ...

  2. 实验报告(一)&第三周总结

    Java实验报告 实验一 Java开发环境与简单Java程序 一. 实验目的 (1)      熟悉JDK开发环境 (2)      熟练掌握结构化程序设计方法 二. 实验内容 1.      打印输 ...

  3. container_of宏解析 && 为什么需要使用中间变量__mptr?

    #define container_of(ptr, type, member) ({ \ )->member ) *__mptr = (ptr); \ (type *)( (char *)__m ...

  4. Mac使用SSH连接远程服务器

    1. 终端通过 ssh 连接远程服务器 ssh -p 36622 root@localhost 2. 文件上传下载 上传 scp 下载 scp 3. 客户端 FinalShell(推荐) FileZi ...

  5. delphi : 窗体的close,free,destroy

    一.我用application.create(TForm2,Form2)语句,创建了Form2,可是调用了Form2.close后,重新调用Form2.show. 刚才所创建的Form2仍然存在.问为 ...

  6. eclipse code recommenders cannot download its model repository index

    Cent OS 7 运行 eclipse oxygen 代码提示出现标题所示的错误,解决办法,将网络提供程序设置为手动即可解决. Window->Preference->General-& ...

  7. yum 下载rpm包 安装rpm包依赖关系

    方法一:yumdownloader 工具 1.安装工具包 yum install yum-utils -y 2.下载一个RPM包 yumdownloader <package-name> ...

  8. Spring Security Session Time Out

    最近在用Spring Security做登录管理,登陆成功后,页面长时间无操作,超过session的有效期后,再次点击页面操作,页面无反应,需重新登录后才可正常使用系统. 为了优化用户体验,使得在se ...

  9. get与post请求的区别 (面试会问)

    get和post请求是HTTP与服务器交互方式,也就是通常所说的风别对服务器资源的增删改查 1. post是修改数据   get是获得数据 GET在浏览器回退时是无害的,而POST会再次提交请求.(面 ...

  10. window10下搭建ELK环境

    面向微服务开发时会涉及到多系统的日志跟踪,一旦出现问题过滤起来系统间切换非常麻烦,所以需要采用特定工具将日志统一归类处理,方便查询排查错误,下面将介绍一种开源的工具ELK. ELK由ElasticSe ...