UVA 10229 Modular Fibonacci
斐波那契取MOD。利用矩阵快速幂取模
http://www.cnblogs.com/Commence/p/3976132.html
代码:
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);} struct node {LL mat[2][2]; }ans,t; LL MOD,N; int M; void init() {ans.mat[0][0]=1;ans.mat[0][1]=0;ans.mat[1][0]=0;ans.mat[1][1]=1;t.mat[0][0]=1;t.mat[0][1]=1;t.mat[1][0]=1;t.mat[1][1]=0;MOD=1<<M; } node mult(node a,node b) {node res;for (int i=0;i<2;i++)for (int j=0;j<2;j++)res.mat[i][j]=(a.mat[i][0]*b.mat[0][j]+a.mat[i][1]*b.mat[1][j])%MOD;return res; } int main() {while (scanf("%lld %d",&N,&M)!=EOF){init();//printf("%lld\n",MOD);while (N){if (N&1) ans=mult(ans,t);t=mult(t,t);N>>=1;}//printf("%lld %lld %lld %lld\n",ans.mat[0][0],ans.mat[0][1],ans.mat[1][0],ans.mat[1][1]);printf("%lld\n",(ans.mat[0][1])%MOD);}return 0; }
转载于:https://www.cnblogs.com/Commence/p/3977853.html
UVA 10229 Modular Fibonacci相关推荐
- UVA10229 Modular Fibonacci 【循环数列】
The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...) are defined by the recurrence: F0 = ...
- UVA 11582 Colossal Fibonacci Numbers!【数学】
大一刚开始接触ACM就买了<算法竞赛入门经典>这本书,当时只能看懂前几章,而且题目也没做,粗鄙地以为这本书不适合自己.等到现在快大三了再回过头来看,发现刘老师还是很棒的! 扯远了... 题 ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
- 提取了下刘汝佳推荐的题号...
今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started 10055 - Hashmat the Brave Warrior ...
- TYUT-A专题题解(一)
TYUT-A专题题解(一) 01A Ad Hoc UVA353 LA5247 Pesky Palindromes[回文] - 海岛Blog - CSDN博客 UVA947 Master Mind He ...
- Competitive Programming 3题解
题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...
- ACM程序设计基础题解
ACM水题一 HDU1262 寻找素数对[素数] - 海岛Blog - CSDN博客 HDU4548 美素数[水题] - 海岛Blog - CSDN博客 HDU2503 a/b + c/d[水题] - ...
- ACM程序设计基础(2)题解
ACM水题二 CodeForces-1A Theatre Square[水题] - 海岛Blog - CSDN博客 AOJ0009 Prime Number[筛选法+前缀和] - 海岛Blog - C ...
- 紫书《算法竞赛入门经典》
紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...
最新文章
- 在将计算机技术应用于会计工作的初期,所开发的会计核算软件主要用于,电算化考前试七.doc...
- 埋点全解 2:iOS 应用程序状态
- Go 语言 cannot find module providing package github.com/
- boost::log模块实现如何同时对多个文件执行日志记录的测试程序
- ONAP发布“阿姆斯特丹”版本,为网络服务自动化制定标准
- 论文浅尝 | 基于知识图谱的子图匹配回答自然语言问题
- 机器学习之数据归一化
- Apache 与 Tomcat 整合
- redux-form(V7.4.2)笔记( 五)核心模块回顾
- VTK:图像阈值用法实战
- 什么是遥远的相似性?
- 约束的操作 - 增加 删除 禁止 启用
- go-http server使用hijack接管连接的管理
- 小沙弥密码箱V1.0
- 中国20顶级富豪惊人挥霍排行榜 仅一家IT老板
- kali Linux的简单介绍
- zabbix + nexmo = 电话告警
- 2020.04.01 【ABAP随笔】- ABAP面试分享
- 《SSO系列二》自己动手写一个SSO
- Linux-根目录(/)的意义与内容