【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. ...
随机推荐
- Linux系统下设置vi编辑器,tab键为4
1.cd ~ 2.vi .exrc 3.set tabstop=4(保存并退出)即可
- <git>……git的基本使用……//
1.切换到存放git版本库的地方 2.Git clone url(github上的地址) 3.设置全局用户(输入一次即可) git config --global user.name github上的 ...
- 7-16 一元多项式求导(20 分)(有关while(scanf("%d",&n)!=EOF))
7-16 一元多项式求导(20 分) 设计函数求一元多项式的导数. 输入格式: 以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数).数字间以空格分隔. 输出格式: 以与输入相同 ...
- [K/3Cloud] 代码中设置某个字段必录
Control ctl = this.GetControl(fieldKey); FieldEditor editCtl = ctl as FieldEditor; if (editCtl != nu ...
- OpenCV在Linux(Fedora)下搭建开发环境简述
盼望了好久的Fedora21终于发行了.先来晒一张图: 默认桌面还是那么简洁: 好了,废话少说.来看看在Fedora下搭建opencv开发环境,因为我已经搭建好了(过程比较艰辛) 先注明参考文章,感谢 ...
- Ubuntu 16.04无法在WPS中输入中文的问题解决
1. sudo gedit /usr/bin/wps 增加 export XMODIFIERS="@im=fcitx" export QT_IM_MODULE="fcit ...
- Ubuntu 16.04桌面打开终端自动进去桌面文件夹
sudo vim ~/.bashrc #在最后添加如下内容,注意,由于我的系统是中文版本,所以文件夹名称为“桌面”,如果为英文版的,那么需要更改为“Desktop” if [[ $PWD == $(r ...
- Ubuntu 16.04安装Markdown编辑器MarkMyWords
继上一篇文章http://www.cnblogs.com/EasonJim/p/7119345.html中使用Sublime Text 3进行Markdown的编辑,总觉得操作上比较繁琐,现在推荐使用 ...
- 断路器监控(Hystrix Dashboard)
继上一篇http://www.cnblogs.com/EasonJim/p/7613595.html介绍了断路器之后,其实它还提供了一个管理页面来监控这些应用的调用数据. 首先,我是基于上一个例子Zo ...
- php-fpm回顾和总结
时间久了很容易忘,这里做个备份 FastCGI协议php语言的实现,可以高效处理来自web端的动态请求 php-fpm维护一个或者多个php-cgi进程池,处理请求时不需要频繁创建进程 所以比传统的C ...