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. ...
随机推荐
- 2011 Multi-University Training Contest 7 - Host by ECNU
AC: F I. rank 40/88. 开场看了F发现是个简单的DP,随便写了一下WA,,,发现把样例倒着输就过不了了...原来是忘了最后的时候开始上课的话可能上不了多久... 想到一个简洁的状态方 ...
- cf Round 587
A.Duff and Weight Lifting(思维) 显然题目中只有一种情况可以合并 2^a+2^a=2^(a+1).我们把给出的mi排序一下,模拟合并操作即可. # include <c ...
- bzoj1835[ZJOI2010]基站选址
主席树+决策单调,重写一遍比之前短多了……题解:http://www.cnblogs.com/liu-runda/p/6051422.html #include<cstdio> #incl ...
- BZOJ4868 Shoi2017期末考试(三分+贪心)
容易想到枚举最晚发布成绩的课哪天发布,这样与ti和C有关的贡献固定.每门课要么贡献一些调节次数,要么需要一些调节次数,剩下的算贡献也非常显然.这样就能做到平方级别了. 然后大胆猜想这是一个凸函数三分就 ...
- Atom Editor 插件 atom-less 的使用方法
一.下载安装 atom-less atom-less 项目在这里:https://github.com/schmuli/atom-less 安装方法请参考这篇博文:http://blog.csdn.n ...
- BZOJ5334:[TJOI2018]数学计算——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=5334 小豆现在有一个数x,初始值为1. 小豆有Q次操作,操作有两种类型: 1 m: x = x ...
- BZOJ4071 & 洛谷3644 & UOJ112:[APIO2015]巴邻旁之桥——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4071 https://www.luogu.org/problemnew/show/P3644 ht ...
- HDOJ.2111 Saving HDU (贪心)
Saving HDU 点我挑战题目 题意分析 给出来背包容量v和物品数量n,接下来n行分别给出每个商品单位体积的价值和物品总共的体积(注意是单位体积,不是每个物品).求出最多能装多少价值的物品. 典型 ...
- NOIP2017金秋冲刺训练营杯联赛模拟大奖赛第二轮Day2题解
肝了两题... T1一眼题,分解质因数,找出2的个数和5的个数取min输出 #include<iostream> #include<cstring> #include<c ...
- HDU1281: 棋盘游戏(二分图匹配)
棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...