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. alidoing --使用JS实现多语言框架、喜欢的请进、、瓦特平台!

    大家好! 多语言实现的案例:http://alidoing.com/或者http://www.alidoing.com/ 图:切换语言界面 JS代码实现: 1.首先新建一个对象langobj,当然对象 ...

  2. Oracle 10g Data Pump Expdp/Impdp 详解

    Data Pump 介绍 在第一部分看了2段官网的说明, 可以看出数据泵的工作流程如下: (1)在命令行执行命令 (2)expdp/impd 命令调用DBMS_DATAPUMP PL/SQL包. 这个 ...

  3. Clickonce - Change deployment URL after publish

    mage.exe -Update C:\inetpub\wwwroot\aspnet40\AminoScience\Uploads\Application Files\AccUFeed_1_0_0_5 ...

  4. selenium - 常用等待操作

    # 4. 等待操作 # 强制等待from time import sleepsleep(10) # 隐性等待# 设置最长等待时间,在这个时间在只要有个时间点加载完成,则执行下一步代码,比sleep智能 ...

  5. python之路 --- python基础

    一.python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC ...

  6. day03_04 文件后缀及系统环境变量

    进入cmd,如果想直接切换盘符的话,操作如下 dir命令---查看目录下的文件及文件夹 cd命令---想进入某个目录,就是是双击文件夹进入目录的命令,按table键有神奇效果哦 cd ..命令---类 ...

  7. PHP define() 定义常量

    PHP define()函数定义了运行时的常量, 具体语法如下所示: (PHP 4, PHP 5, PHP 7) define — Defines a named constant bool defi ...

  8. Scrum基础知识图谱

    啰嗦一下 最近在学习scrum项目管理的知识,书上知识点分散,很难有整体的视角来看scrum有哪些核心知识,故制作了思维导图,望给和我一样容易迷失的人一样,起到一个指引作用,废话不多说,直接上图 图谱

  9. URAL 1137Bus Routes (dfs)

    Z - Bus Routes Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  10. HDU——4162Shape Number(字符串的最小表示)

    Shape Number Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...