UVA 11885 - Number of Battlefields(斐波那契)
11885 - Number of Battlefields
。。
#include <stdio.h>
#include <string.h> const long long MOD = 987654321;
int p; struct mat {
long long v[2][2];
mat() {memset(v, 0, sizeof(v));}
mat operator *(mat c) {
mat ans;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
ans.v[i][j] = (ans.v[i][j] + v[i][k] * c.v[k][j] % MOD) % MOD;
}
}
}
return ans;
}
mat operator^(int k) {
mat x = *this, ans;
ans.v[0][0] = ans.v[1][1] = 1;
while (k) {
if (k&1)
ans = ans * x;
x = x * x;
k >>= 1;
}
return ans;
}
}; int main() {
while (~scanf("%d", &p) && p) {
if(p % 2) {printf("0\n"); continue;}
mat pri;
pri.v[0][0] = pri.v[0][1] = pri.v[1][0] = 1;
pri = pri^(p - 4);
printf("%lld\n",(pri.v[0][0] - ((long long)p / 2 - 1) + MOD) % MOD);
}
return 0;
}
UVA 11885 - Number of Battlefields(斐波那契)的更多相关文章
- uva 11885 - Number of Battlefields(矩阵高速幂)
题目连接:uva 11885 - Number of Battlefields 题目大意:给出周长p,问多少种形状的周长为p的,而且该图形的最小包围矩阵的周长也是p,不包含矩形. 解题思路:矩阵高速幂 ...
- HDU 1005 Number Sequence【斐波那契数列/循环节找规律/矩阵快速幂/求(A * f(n - 1) + B * f(n - 2)) mod 7】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Tribonacci UVA - 12470 (简单的斐波拉契数列)(矩阵快速幂)
题意:a1=0;a2=1;a3=2; a(n)=a(n-1)+a(n-2)+a(n-3); 求a(n) 思路:矩阵快速幂 #include<cstdio> #include<cst ...
- python基础----斐波那契数列
python实现斐波那契数列的三种方法 """ 斐波那契数列 0,1,1,2,3,5,8,13,21,... """ # 方法一:while ...
- (斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)
根据CC150的解决方式和Introduction to Java programming总结: 使用了两种方式,递归和迭代 CC150提供的代码比较简洁,不过某些细节需要分析. 现在直接运行代码,输 ...
- [LeetCode] Fibonacci Number 斐波那契数字
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...
- [Swift]LeetCode509. 斐波那契数 | Fibonacci Number
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...
- UVA 11582 Colossal Fibonacci Numbers! 大斐波那契数
大致题意:输入两个非负整数a,b和正整数n.计算f(a^b)%n.其中f[0]=f[1]=1, f[i+2]=f[i+1]+f[i]. 即计算大斐波那契数再取模. 一开始看到大斐波那契数,就想到了矩阵 ...
- hdu number number number 斐波那契数列 思维
http://acm.hdu.edu.cn/showproblem.php?pid=6198 F0=0,F1=1的斐波那契数列. 给定K,问最小的不能被k个数组合而成的数是什么. 赛后才突然醒悟,只要 ...
随机推荐
- Codeforces 915 E Physical Education Lessons
题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...
- 1.1(学习笔记)JSP(Java Server Pages)基础(脚本元素、指令元素)
一.JSP简介 JSP全称为Java Server Pages,是一种动态网页开发技术,可以在HTML界面中嵌入java代码, 实现动态的提供数据.访问JSP时服务器会将JSP翻译成Servlet,访 ...
- 【OpenJudge8464】【序列DP】股票买卖
股票买卖 总时间限制: 1000ms 内存限制: 65536kB [描述] 最近越来越多的人都投身股市,阿福也有点心动了.谨记着“股市有风险,入市需谨慎”,阿福决定先来研究一下简化版的股票买卖问题. ...
- 多IDC GSLB的部署 - ADC技术博客 - 51CTO技术博客
多IDC GSLB的部署 - ADC技术博客 - 51CTO技术博客 A10
- js时间小总结
1.js获取时间 var myDate = new Date(); 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getFullYear(); //获取完整的年份 ...
- Yasm 1.3.0 Release Notes
Yasm 1.3.0 Release Notes http://yasm.tortall.net/releases/Release1.3.0.html Target Audience Welcome ...
- Win7如何自定义桌面右键菜单
1 在注册表的HKEY_CLASSES_ROOT\DesktopBackground\Shell\位置,我们新建一个计算器,他的下面有一个项目command,然后这个command去打开计算器(通过分 ...
- 用聚合数据API(苏州实时公交API)快速写出小程序
利用聚合数据API快速写出小程序,过程简单. 1.申请小程序账号 2.进入开发 3.调用API.比如“苏州实时公交”小程序,选择的是苏州实时公交API. 苏州实时公交API文档:https://www ...
- ngnix学习视频
https://www.bilibili.com/video/av36019080/?p=1
- IE 页面不正常显示 错误脚本不报错 脚本调试相关
在开发时,有时自己做的页面上的JS有错误,但是IE浏览器并不报错,这个时候有可能是因为脚本调试被禁止了. 在Internet选项的高级里面有 两个禁止脚本调试选项,把他们去掉就行.