HDU2256-Problem of Precision(矩阵构造+高速幂)
题意:求sqrt(sqrt(2) + sqrt(3)) ^ 2n MOD 1024
思路:

代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; const int MOD = 1024; int n; struct mat {
int s[2][2];
mat(int a = 0, int b = 0, int c = 0, int d = 0) {
s[0][0] = a;
s[0][1] = b;
s[1][0] = c;
s[1][1] = d;
}
mat operator * (const mat& c) {
mat ans;
sizeof(ans.s, 0, sizeof(ans.s));
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++)
ans.s[i][j] = (ans.s[i][j] + s[i][k] * c.s[k][j]) % MOD;
return ans;
}
}tmp(5, 12, 2, 5); mat pow_mod(int k) {
if (k == 1)
return tmp;
mat a = pow_mod(k / 2);
mat ans = a * a;
if (k % 2)
ans = ans * tmp;
return ans;
} int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d", &n);
mat ans = pow_mod(n);
printf("%d\n", (ans.s[0][0] * 2 - 1) % MOD);
}
return 0;
}
HDU2256-Problem of Precision(矩阵构造+高速幂)的更多相关文章
- HDU 2256 Problem of Precision(矩阵高速幂)
题目地址:HDU 2256 思路: (sqrt(2)+sqrt(3))^2*n=(5+2*sqrt(6))^n; 这时要注意到(5+2*sqrt(6))^n总能够表示成an+bn*sqrt(6); a ...
- poj3070--Fibonacci(矩阵的高速幂)
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9650 Accepted: 6856 Descrip ...
- HDU 2256 Problem of Precision(矩阵)
Problem of Precision [题目链接]Problem of Precision [题目类型]矩阵 &题解: 参考:点这里 这题做的好玄啊,最后要添加一项,之后约等于,但是有do ...
- HDU 2256 Problem of Precision (矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256 最重要的是构建递推式,下面的图是盗来的.貌似这种叫共轭数. #include <iostr ...
- HDU 2256 Problem of Precision (矩阵快速幂)(推算)
Problem of Precision Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- LightOJ 1070 - Algebraic Problem 矩阵高速幂
题链:http://lightoj.com/volume_showproblem.php?problem=1070 1070 - Algebraic Problem PDF (English) Sta ...
- LightOJ 1070 Algebraic Problem (推导+矩阵高速幂)
题目链接:problem=1070">LightOJ 1070 Algebraic Problem 题意:已知a+b和ab的值求a^n+b^n.结果模2^64. 思路: 1.找递推式 ...
- poj 2778 AC自己主动机 + 矩阵高速幂
// poj 2778 AC自己主动机 + 矩阵高速幂 // // 题目链接: // // http://poj.org/problem?id=2778 // // 解题思路: // // 建立AC自 ...
- HDU 5411 CRB and puzzle (Dp + 矩阵高速幂)
CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
随机推荐
- oracle 控制文件的重建
目录 oracle 控制文件的重建 NORESETLOGS RESETLOGS oracle 控制文件的重建 不到最后时刻,如三个控制文件都已损坏,又没有控制文件的备份.还是不要重建控制文件,处理不好 ...
- [转] 查看 SELinux状态及关闭SELinux
本文转载自: http://bguncle.blog.51cto.com/3184079/957315 查看SELinux状态: 1./usr/sbin/sestatus -v ##如果SE ...
- ogre的初始化与启动以及显示对象设置
ogre的使用方法1---自动设置 1.ogre初始化:首先实例化一个Root对象 Root * root = new Root(); Root * root = new Root("plu ...
- Map容器——TreeMap及常用API,Comparator和Comparable接口
TreeMap及常用API ① TreeMap类通过使用红黑树实现Map接口; ② TreeMap提供按排序顺序存储键/值对的有效手段,同时允许快速检索; ③ 不像散列(HashMap), ...
- 微软工具Sysinternals Suite
工具:Sysinternals Suite 一个可以看进程的工具.
- 国外12家值得注意的SD-WAN厂商
国外12家值得注意的SD-WAN厂商 来源 https://www.sdnlab.com/18611.html 在网络行业,围绕软件定义网络的炒作似乎已经殆尽,但业界普遍对软件定义广域网(SD-WAN ...
- [LOJ#525]「LibreOJ β Round #4」多项式
[LOJ#525]「LibreOJ β Round #4」多项式 试题描述 给定一个正整数 k,你需要寻找一个系数均为 0 到 k−1 之间的非零多项式 f(x),满足对于任意整数 x 均有 f(x) ...
- 2017.8.12 dp课小结
这节课难度超级大啊,基本上都是省选+NOI的题. 例1: 1801: [Ahoi2009]chess 中国象棋 Time Limit: 10 Sec Memory Limit: 64 MB Subm ...
- [POJ2417]Discrete Logging(指数级同余方程)
Discrete Logging Given a prime P, 2 <= P < 2 31, an integer B, 2 <= B < P, and an intege ...
- java集合四种遍历方式
package conection; import java.util.Iterator;import java.util.LinkedList;import java.util.List; publ ...