51nod1242 斐波那契数列 矩阵快速幂
#include<stdio.h>
#define mod 1000000009
struct node{
long long int c[][];
} t;
long long int n;
node mul(node a,node b){//矩阵乘法
node c;
int i,j,k;
for(i=;i<;i++){
for(j=;j<;j++){
c.c[i][j]=;
for(k=;k<;k++)
c.c[i][j]+=(a.c[i][k]*b.c[k][j])%mod;
c.c[i][j]=c.c[i][j]%mod;
}
}
return c;
}
node kuaisumi(long long int n){
node res = t;
if(n<)
return res;
while(n){
if(n&)
res=mul(res,t);
t=mul(t,t);
n=n>>;
}
return res;
}
int main(){
while(~scanf("%lld",&n)){
t.c[][] = ;
t.c[][] = ;
t.c[][] = ;
t.c[][] = ;
node res=kuaisumi(n-);
printf("%lld\n",res.c[][]);
}
}
输入1个数n(1 <= n <= 10^18)。
输出F(n) % 1000000009的结果。
11
89
51nod1242 斐波那契数列 矩阵快速幂的更多相关文章
- HDU4549 M斐波那契数列 矩阵快速幂+欧拉函数+欧拉定理
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- POJ3070 斐波那契数列 矩阵快速幂
题目链接:http://poj.org/problem?id=3070 题意就是让你求斐波那契数列,不过n非常大,只能用logn的矩阵快速幂来做了 刚学完矩阵快速幂刷的水题,POJ不能用万能头文件是真 ...
- hdu4549 M斐波那契数列 矩阵快速幂+快速幂
M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n]的 ...
- 洛谷P1962 斐波那契数列(矩阵快速幂)
题目背景 大家都知道,斐波那契数列是满足如下性质的一个数列: • f(1) = 1 • f(2) = 1 • f(n) = f(n-1) + f(n-2) (n ≥ 2 且 n 为整数) 题目描述 请 ...
- hdu 4549 M斐波那契数列 矩阵快速幂+欧拉定理
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Problem ...
- POJ 3070 Fibonacci【斐波那契数列/矩阵快速幂】
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17171 Accepted: 11999 Descr ...
- hdu 4549 M斐波拉契 (矩阵快速幂 + 费马小定理)
Problem DescriptionM斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 ) 现在 ...
- 洛谷- P1306 斐波那契公约数 - 矩阵快速幂 斐波那契性质
P1306 斐波那契公约数:https://www.luogu.org/problemnew/show/P1306 这道题目就是求第n项和第m项的斐波那契数字,然后让这两个数求GCD,输出答案的后8位 ...
- POJ 3070(求斐波那契数 矩阵快速幂)
题意就是求第 n 个斐波那契数. 由于时间和内存限制,显然不能直接暴力解或者打表,想到用矩阵快速幂的做法. 代码如下: #include <cstdio> using namespace ...
随机推荐
- 解决Please ensure that adb is correctly located at 'D:\java\sdk\platform-tools\adb.exe' and can be executed.
遇到问题描述: 运行android程序控制台输出 [2012-07-18 16:18:26 - ] The connection to adb is down, and a severe error ...
- yii 2.0 代码阅读 小记
1.\yii\base\object 设置了get/set属性...使用getName()获取属性名..构造函数中使用config初始化属性 2.\yii\base\Component 继承自Obje ...
- 面试题总结之JAVA
JAVA 1. what is thread safe? 线程安全就是说多线程访问同一代码,不会产生不确定的结果.编写线程安全的代码是低依靠线程同步.线程安全: 在多线程中使用时,不用自已做同步处理线 ...
- 文件I/O(不带缓冲)之open函数
调用open函数可以打开或创建一个文件. #include <fcntl.h> int open( const char *pathname, int oflag, ... /* mode ...
- Tomcat 配置 Probe 监控
转至:http://9771104.blog.163.com/blog/static/19446622009811112836524/ 手上接触Tomcat的项目越来越多,虽说tomcat的manag ...
- javascript简单笔记
js有一个非常好用的内置处理小数点函数,a.toFixed(2). 调试代码常用:console.log(var); 返回上一级,并重新加载页面 window.location.href = docu ...
- Middleware
Middleware The middleware gives a single shot to the views associated into Controllers, before execu ...
- centos nginx和tomcat 通过反向代理生成想要的nexus网址
研究背景: 最近一直在研究maven nexus 私服,所以想在自己带老笔记本上搭建一个私服,看到网上很多私服都有自己带域名,所以想在搭建过程中通过修改host 生成想要带域名 成功截图: 操作步骤: ...
- jsp 用application对象制作留言板
<%@ page contentType="text/html; charset=gb2312"%> <html> <body> <for ...
- debian 开启SSH
1.修改sshd_config文件,命令为:vi /etc/ssh/sshd_config 2.将#PasswordAuthentication no的注释去掉,并且将NO修改为YES //我的ka ...