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. 解决debian 9 重启nameserver失效问题

    目录 解决debian 9 重启nameserver失效问题 安装resolvconf 编辑文件 测试 解决debian 9 重启nameserver失效问题 刚安装完debian9,用过之后会发现/ ...

  2. 常用软件URL

    1.MSDN:https://msdn.itellyou.cn/ 2.软碟通(UltraISO)http://rj.baidu.com/soft/detail/11522.html?ald Ultra ...

  3. [uiautomator篇] 如何获取apk的包名 博客模板

    Android自动化学习笔记:获取APK包名的几种方法 ------------------------------------------------------------------------ ...

  4. TOJ1017: Tour Guide

      描述 You are working as a guide on a tour bus for retired people, and today you have taken your regu ...

  5. 常见shell脚本命令整理

    1.cat /dev/null > test.txt txt的文件内容被清空. 2.ls | xargs rm 目录中大量文件的删除 3.查看文件夹下文件个数 ls | wc -w 查看有多少个 ...

  6. MySQL可供选择的存储引擎

    备注:以下关于5.7版本的内容是来源于官方文档:https://dev.mysql.com/doc/refman/5.7/en/storage-engines.html 以下关于5.6版本的内容,一部 ...

  7. HDU-2413 Against Mammoths

    二分答案,对于当前答案Ans,求出某些人类可打败某些外星人的对应边,建图后求是否有完备匹配. //#include <cmath> #include <cstdlib> #in ...

  8. 【BZOJ1101】Zap(莫比乌斯反演)

    题意:多组询问,对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d. T,a,b,d,x,y<=50000 思路:下底函数分块+积性函数 ...

  9. 如何让div中的文字只显示一行,多余的文字隐藏并加上省略号(超链接形式)

    写页面的时候遇到了一个小小的问题,如何让div中一行超链接文字只显示一行,多余的文字隐藏并加上省略号,悬浮时隐藏的文字显示出来?解决问题时发现了css3的一个新标签  text-overflow  , ...

  10. 关于toggle的用法

    //一个关于鼠标点击 切换场景的代码段 $(document).on('click', '.create-advice-elseparm', function () { $('.advice-else ...