【POJ 3070】 Fibonacci
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
const long long MOD = ; long long n;
struct Matrix
{
long long n,m;
long long mat[][];
} ans; inline void multipy(Matrix &a,Matrix b)
{
long long i,j,k;
Matrix ans;
ans.n = a.n; ans.m = b.m;
memset(ans.mat,,sizeof(ans.mat));
for (i = ; i <= a.n; i++)
{
for (j = ; j <= b.m; j++)
{
for (k = ; k <= a.m; k++)
{
ans.mat[i][j] = (ans.mat[i][j] + a.mat[i][k] * b.mat[k][j]) % MOD;
}
}
}
a = ans;
} inline void power(Matrix &a,long long n)
{
Matrix p,ans;
p.n = p.m = ;
p.mat[][] = ; p.mat[][] = ;
p.mat[][] = ; p.mat[][] = ;
ans.n = ans.m = ;
ans.mat[][] = ; ans.mat[][] = ;
ans.mat[][] = ; ans.mat[][] = ;
while (n > )
{
if (n & ) multipy(ans,p);
n >>= ;
multipy(p,p);
}
a = ans;
} inline void solve()
{
Matrix tmp;
tmp.n = ; tmp.m = ;
tmp.mat[][] = ; tmp.mat[][] = ;
ans.n = ans.m = ;
ans.mat[][] = ans.mat[][] = ans.mat[][] = ;
ans.mat[][] = ;
power(ans,n-);
multipy(ans,tmp);
cout<< ans.mat[][] << endl;
} int main()
{ while (scanf("%lld",&n) != EOF && n != -)
{
if (!n) cout<< << endl;
else if (n == ) cout<< << endl;
else solve();
} return ;
}
【POJ 3070】 Fibonacci的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- react初探索--react + react-router + ant-design 后台管理系统配置
首先确认安装了node环境,Node >= 6. 如果对react 及 ant-design 一无所知,建议去阅读下api文档,react 可以在 codePen 在线练习. react Api ...
- 程序包javax.servlet.http不存在
在maven test项目时,出现错误: java:[7,26] 程序包javax.servlet.http不存在 原因:pom.xml中未引入javax.servlert-api相关的包 <d ...
- 集训第六周 M题
Description During the early stages of the Manhattan Project, the dangers of the new radioctive ma ...
- LeetCode 188. Best Time to Buy and Sell Stock IV (stock problem)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 全文检索(AB-1)-相关领域
信息检索 认知科学 管理科学
- NYOJ-770仿射密码,乘数密码与移位密码的结合;
仿射密码 时间限制:1000 ms | 内存限制:65535 KB 难度:1 -> Link <- 和乘数密码差不多: 加密算法:Ek(m)=(k1*m+k2)%q;gcd(k ...
- C语言不容易识别的坑
1.重复两次定义 #include<stdio.h> #include<stdlib.h> #include<string.h> int a,b; void fun ...
- 动态规划之最长递增子序列(LIS)
在一个已知的序列{ a1,a2,……am}中,取出若干数组成新的序列{ ai1, ai2,…… aim},其中下标 i1,i2, ……im保持递增,即新数列中的各个数之间依旧保持原数列中 ...
- 找出消耗CPU最高的进程对应的SQL语句
COLUMN PID FORMAT 999COLUMN S_# FORMAT 999COLUMN USERNAME FORMAT A9 HEADING "ORA USER"COLU ...
- Linux下汇编语言学习笔记45 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...