pid=2256">题目链接

题意:求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(矩阵构造+高速幂)的更多相关文章

  1. 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 ...

  2. poj3070--Fibonacci(矩阵的高速幂)

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9650   Accepted: 6856 Descrip ...

  3. HDU 2256 Problem of Precision(矩阵)

    Problem of Precision [题目链接]Problem of Precision [题目类型]矩阵 &题解: 参考:点这里 这题做的好玄啊,最后要添加一项,之后约等于,但是有do ...

  4. HDU 2256 Problem of Precision (矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256 最重要的是构建递推式,下面的图是盗来的.貌似这种叫共轭数. #include <iostr ...

  5. HDU 2256 Problem of Precision (矩阵快速幂)(推算)

    Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. LightOJ 1070 - Algebraic Problem 矩阵高速幂

    题链:http://lightoj.com/volume_showproblem.php?problem=1070 1070 - Algebraic Problem PDF (English) Sta ...

  7. LightOJ 1070 Algebraic Problem (推导+矩阵高速幂)

    题目链接:problem=1070">LightOJ 1070 Algebraic Problem 题意:已知a+b和ab的值求a^n+b^n.结果模2^64. 思路: 1.找递推式 ...

  8. poj 2778 AC自己主动机 + 矩阵高速幂

    // poj 2778 AC自己主动机 + 矩阵高速幂 // // 题目链接: // // http://poj.org/problem?id=2778 // // 解题思路: // // 建立AC自 ...

  9. HDU 5411 CRB and puzzle (Dp + 矩阵高速幂)

    CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

随机推荐

  1. 面试中注意3个javascript的问题

    JavaScript 是所有现代浏览器的官方语言.因此,各种语言的开发者面试中都会遇到 JavaScript 问题. 本文不讲最新的 JavaScript 库,通用开发实践,或任何新的 ES6 函数. ...

  2. dp好题 玲珑杯 Expected value of the expression

    152 - Expected value of the expression Time Limit:2s Memory Limit:128MByte Submissions:135Solved:65 ...

  3. TOJ2712: Atlantis

    小数据求面积并 There are several ancient Greek texts that contain descriptions of the fabled island Atlanti ...

  4. you build it,you run it

    this article is almostly about  a book named Migrating_to_Microservices_Databases, and it's just the ...

  5. PHPSTORM+Thinkphp3.2模板标签替换Thinkphp5.1公式

    FORMAT: purpose: find: replace 替换<php>标签 <php>(.*)</php> {php}$1{/php} 替换<if &g ...

  6. 在Ubuntu中,用mvn打包hadoop源代码时报错,正在解决中!!!

    报错信息如下: (各种配置在最后面) hadoop@administrator-virtual-machine:~/Downloads/tar/hadoop-3.0.0-alpha1-src$ mvn ...

  7. 【bzoj2150】部落战争 有上下界最小流

    题目描述 lanzerb的部落在A国的上部,他们不满天寒地冻的环境,于是准备向A国的下部征战来获得更大的领土. A国是一个M*N的矩阵,其中某些地方是城镇,某些地方是高山深涧无人居住.lanzerb把 ...

  8. [CQOI2010] 扑克牌 (二分答案,巧解)

    Description 你有n种牌,第i种牌的数目为ci.另外有一种特殊的牌:joker,它的数目是m.你可以用每种牌各一张来组成一套牌,也可以用一张joker和除了某一种牌以外的其他牌各一张组成1套 ...

  9. Java面试题之HashMap如何有效减少碰撞

    1.扰动函数算法,促使元素位置分布均匀,减少碰撞几率: 2.使用final对象,并采用合适的equals方法和hashCode方法:

  10. 【CF387D】George and Interesting Graph(二分图最大匹配)

    题意:给定一张n点m边没有重边的有向图,定义一个有趣图为:存在一个中心点满足以下性质: 1.除了这个中心点之外其他的点都要满足存在两个出度和两个入度. 2.中心 u 需要对任意顶点 v(包括自己)有一 ...