sicily 1001. Fibonacci 2
The input test file will contain a single line containing n (n ≤ 2^31-1).
There are multiple test cases!
For each test case, print the Fn mod (10^9 + 7).
9
34 用矩阵快速幂的方法,具体可见: http://blog.csdn.net/ACdreamers/article/details/25616461
#include <iostream> using namespace std; #define M 1000000007 struct Matrix{
long long v[][];
}; Matrix matrixMul(Matrix a, Matrix b) {
Matrix temp;
for (int i = ; i != ; i++) {
for (int j = ; j != ; j++) {
temp.v[i][j] = ;
for (int k = ; k != ; k++) {
temp.v[i][j] += a.v[i][k] * b.v[k][j];
temp.v[i][j] %= M;
}
}
}
return temp;
} Matrix power(Matrix a, Matrix b, long long n) {
while (n) {
if (n & ) {
b = matrixMul(b, a);
}
n >>= ;
a = matrixMul(a, a);
}
return b;
} int main(int argc, char* argv[])
{
Matrix a = {, , , }, b = {, , , };
long long n;
while (cin >> n) {
if (n == )
cout << << endl;
else {
Matrix result = power(a, b, n - );
cout << result.v[][] << endl;
}
} return ;
}
sicily 1001. Fibonacci 2的更多相关文章
- BestCoder10 1001 Revenge of Fibonacci(hdu 5018) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 题目意思:给出在 new Fibonacci 中最先的两个数 A 和 B(也就是f[1] = A ...
- <Sicily>Fibonacci 2
一.题目描述 In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn-1 + Fn-2 for n ≥ 2. For exampl ...
- <Sicily>Fibonacci
一.题目描述 In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn-1 + Fn-2 for n ≥ 2. For exampl ...
- 学习笔记之1001 Inventions That Changed the World
1001 Inventions That Changed the World: Jack Challoner: 9780764161360: Amazon.com: Books https://www ...
- 大菲波数(Fibonacci)java大数(hdu1715)
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...
- BNU 13024 . Fi Binary Number 数位dp/fibonacci数列
B. Fi Binary Number A Fi-binary number is a number that contains only 0 and 1. It does not conta ...
- ACM-SG函数之Fibonacci again and again——hdu1848
Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- 算法与数据结构(九) 查找表的顺序查找、折半查找、插值查找以及Fibonacci查找
今天这篇博客就聊聊几种常见的查找算法,当然本篇博客只是涉及了部分查找算法,接下来的几篇博客中都将会介绍关于查找的相关内容.本篇博客主要介绍查找表的顺序查找.折半查找.插值查找以及Fibonacci查找 ...
- #26 fibonacci seqs
Difficulty: Easy Topic: Fibonacci seqs Write a function which returns the first X fibonacci numbers. ...
随机推荐
- 【bzoj1370】[Baltic2003]Gang团伙 并查集
题目描述 在某城市里住着n个人,任何两个认识的人不是朋友就是敌人,而且满足: 1. 我朋友的朋友是我的朋友: 2. 我敌人的敌人是我的朋友: 所有是朋友的人组成一个团伙.告诉你关于这n个人的m条信息, ...
- JavaScript词法分析解析
函数在调用之前,会进行词法分析或者叫语法分析: 1. 函数在形成调用的那一瞬间,会有一个活动对象叫 active object ,简称AO,会分析如下几条: 形式参数 函数内局部变量声明 函数声明表达 ...
- 【原创】Oracle Not In 导致有存在Null的数据被过滤
解决方法: WHERE NVL(ID,) NOT IN ('') 注:红字部分不相等就可以
- I/O复用----poll
2018-08-01 (星期三)poll(): #include <sys/poll.h> int poll (struct pollfd *fd, unsigned int nfds, ...
- 【题解】Uoj79一般图最大匹配
带花树裸题,感觉带花树强强……不会的勿看此文,解释的可能不对,只是给自己看的!!!如题,带花树即为求一般图最大匹配算法(匈牙利与dinic为二分图最大匹配).推荐论文:2015年<浅谈图的匹配算 ...
- BZOJ4144 [AMPPZ2014]Petrol 【最短路 + 最小生成树】
题目链接 BZOJ4144 题解 这题好妙啊,,orz 假设我们在一个非加油站点,那么我们一定是从加油站过来的,我们剩余的油至少要减去这段距离 如果我们在一个非加油站点,如果我们到达不了任意加油站点, ...
- 学习web安全之--初识安全
随笔:随着互联网行业的飞速发展,互联网行业可谓日新月异,然而在繁华的背后,大多的互联网公司对于网络安全还是处于无重视,不作为的阶段,而作为一个程序员,如果也对信息安全视而不见的话,那将是这个公司的噩梦 ...
- 【HASH】【UVA 10125】 Sumset
传送门 Description 给定一个整数集合S,求一个最大的d,满足a+b+c=d,其中a,b,c,d∈S Input 多组数据,每组数据包括: 第一行一个整数n,代表元素个数 下面n行每行一个整 ...
- django error: DisallowedHost: Invalid HTTP_HOST header: ''. You may need to add u'' to ALLOWED_HOST
测试环境: [root@nanx-lli ~]# lsb_release -aLSB Version: :core-4.1-amd64:core-4.1-noarchDistributor ID: C ...
- 【IntelliJ IDEA 12使用】导入外部包
以前用eclipse,现在用IntelliJ IDEA,发现它确实是个很不错的工具. 用IntelliJ IDEA12这个版本导入外部JAR包,这样来操作,打开Project Structure,在m ...