【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. ...
随机推荐
- YUM:Yellow dog Updater Modified
1. 什么是YUM YUM(全称为 Yellow dog Updater Modified) 是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器.基于RPM包管理,能够从 ...
- 树莓派 - gpio-led platform driver 控制LED
树莓派3b板上有两个LED, pwr (power) 和 act (activity).是platform_driver gpio-led驱动. 可以通过设备树和gpio-led来额外控制一个LED. ...
- linux目录文件操作
一.linux系统目录结构 1.顶层根目录 顶层根目录使用 “/”来表示 2.linux中的一些重要目录 (1)bin目录 放置常用的可执行文件(其中ls命令位列其中) (2)sbin目录 放置系统的 ...
- rbac组件之菜单操作(三)
菜单包括菜单列表,菜单列表不仅将菜单列出来,而且将每个菜单下的权限也列出来.菜单的添加.删除.修改. urls.py ... re_path(r'^menus/list/$', MenuView.as ...
- 在移动端H5开发中(关于安卓端position:fixed和position:absolute;和虚拟键盘冲突的问题,以及解决方案)
一.在开发移动端webapp时,我们经常会遇到这样的问题,当我们需要在页面底部固定一个logo或者说明时,往往会采用position:fixed进行固定定位或者absolute定位到最底部 这是一个很 ...
- LeetCode(48)Rotate Image
题目 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise ...
- UVa 514 铁轨
题意: #include <bits/stdc++.h> using namespace std; int main() { int n; ]; ; ) { ]) && n ...
- 【Codeforces 1086B】Minimum Diameter Tree
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 统计叶子节点个数m 把每条和叶子节点相邻的边权设置成s/cnt就可以了 这样答案就是2*s/m(直径最后肯定是从一个叶子节点开始,到另外一个叶 ...
- 九度oj 题目1181:遍历链表
题目1181:遍历链表 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3483 解决:1465 题目描述: 建立一个升序链表并遍历输出. 输入: 输入的每个案例中第一行包括1个整数:n(1 ...
- HTML Imports & polyfill
组件化浏览器的兼容性问题汇总 框架依赖的 Web 标准技术 优先级高 HTML Imports HTML tempaltes ES6 to ES5 (搭建模块开发环境) polyfill https: ...