题意

求$(\sqrt{2} + \sqrt{3})^{2n} \pmod {1024}$

$n \leqslant 10^9$

Sol

看到题解的第一感受:这玩意儿也能矩阵快速幂???

是的,它能qwq。。。。

首先我们把$2$的幂乘进去,变成了

$(5 + 2\sqrt{6})^n$

设$f(n) = A_n + \sqrt{6} B_n$

那么$f(n+1) = (A_n + \sqrt{6} B_n ) * (5 + 2\sqrt{6})$

乘出来得到

$A_{n + 1} = 5 A_n + 12 B_n$

$B_{n + 1} = 2A_n + B B_n$

那么不难得到转移矩阵

$$\begin{pmatrix} 5 & 12 \\ 2 & 5 \end{pmatrix}$$

这样好像就能做了。。

但是实际上后我们最终会得到一个类似于$A_n + \sqrt{6}B_n$的东西,这玩意儿还是不能取模

考虑如何把$\sqrt{6}$的影响消掉。

$(5 + 2 \sqrt{6})^n = A_n + \sqrt{6}B_n$

$(5 - 2 \sqrt{6})^n = A_n - \sqrt{6}B_n$

相加得

$(5 + 2 \sqrt{6})^n + (5 - 2 \sqrt{6})^n = 2A_n$

考虑到$0 < (5 - 2\sqrt{6})^n < 1$

那么

$$\lfloor (5 + 2\sqrt{6})^n \rfloor = 2A_n - 1$$

做完啦qwq

#include<cstdio>
#include<cstring>
#include<iostream>
#define Pair pair<int, int>
#define MP(x, y)
#define fi first
#define se second
// #include<map>
using namespace std;
#define LL long long
const LL MAXN = , mod = ;
inline LL read() {
char c = getchar(); LL x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int T, N;
struct Matrix {
LL m[][], N;
Matrix() {N = ; memset(m, , sizeof(m));}
Matrix operator * (const Matrix &rhs) const {
Matrix ans;
for(int k = ; k <= N; k++)
for(int i = ; i <= N; i++)
for(int j = ; j <= N; j++)
(ans.m[i][j] += 1ll * m[i][k] * rhs.m[k][j] % mod) % mod;
return ans;
}
}; Matrix fp(Matrix a, int p) {
Matrix base; base.m[][] = ; base.m[][] = ;
while(p) {
if(p & ) base = base * a;
a = a * a; p >>= ;
}
return base;
}
int main() {
T = read();
while(T--) {
N = read();
Matrix a;
a.m[][] = ; a.m[][] = ;
a.m[][] = ; a.m[][] = ;
a = fp(a, N - );
LL ans = ( * a.m[][] + * a.m[][]) % mod;
printf("%I64d\n", ( * ans - ) % mod);
}
return ;
} /**/

HDU 2256Problem of Precision(矩阵快速幂)的更多相关文章

  1. HDU.1575 Tr A ( 矩阵快速幂)

    HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. ...

  2. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  3. HDU 2842 (递推+矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...

  4. hdu 2604 Queuing(矩阵快速幂乘法)

    Problem Description Queues and Priority Queues are data structures which are known to most computer ...

  5. HDU 5950 - Recursive sequence - [矩阵快速幂加速递推][2016ACM/ICPC亚洲区沈阳站 Problem C]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with ...

  6. 2013长春网赛1009 hdu 4767 Bell(矩阵快速幂+中国剩余定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4767 题意:求集合{1, 2, 3, ..., n}有多少种划分情况bell[n],最后结果bell[ ...

  7. HDU 6470 Count 【矩阵快速幂】(广东工业大学第十四届程序设计竞赛 )

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6470 Count Time Limit: 6000/3000 MS (Java/Others)    ...

  8. HDU 6395 Sequence 【矩阵快速幂 && 暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)   ...

  9. HDU 5667 Sequence【矩阵快速幂+费马小定理】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5667 题意: Lcomyn 是个很厉害的选手,除了喜欢写17kb+的代码题,偶尔还会写数学题.他找到 ...

随机推荐

  1. 重学JAVA基础(四):线程的创建与执行

    1.继承Thread public class TestThread extends Thread{ public void run(){ System.out.println(Thread.curr ...

  2. AI-Info-Micron-Insight:高速数据:第四次工业革命的助推引擎

    ylbtech-AI-Info-Micron-Insight:高速数据:第四次工业革命的助推引擎 1.返回顶部 1. 高速数据:第四次工业革命的助推引擎 第四次工业革命已然来临,因为数字技术几乎连接了 ...

  3. MangoDB篇章(1)

    关系型数据库遵循ACID规则 事务(transaction)4个特性:原子性(A).一致性(C).独立性(I).持久性(D) : 分布式系统(distributed system): 由多台计算机和通 ...

  4. C# 清除cookies

    不同的浏览器会把cookie文件保存在不同的地方 以下是C# WebBrowser控件cookies的存放路径 C:\Users\{你的帐号名}\AppData\Local\Microsoft\Win ...

  5. HDOj-1412

    {A} + {B} Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. 利用JS函数制作时钟运行程序

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Spring Boot错误errMsg: "request:ok"

    在把评论写到数据库并且动态刷新评论区的时候,有时候正常写入,有时候就会有“request:ok”的的错误出现,错误信息如下: data: {timestamp: , error: "Inte ...

  8. 牛客月赛 G-many sum(筛因子)

    many sum 链接:https://ac.nowcoder.com/acm/contest/879/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K, ...

  9. QDUOJ 来自xjy的签到题(bfs+状压dp)

    来自xjy的签到题   Description 爱丽丝冒险来到了红皇后一个n*n大小的花园,每个格子由'.'或'#'表示,'.'表示爱丽丝可以到达这个格子,‘#’表示爱丽丝不能到达这个格子,爱丽丝每1 ...

  10. Node.js 内置模块fs的readdir方法 查看某个文件夹里面包含的文件内容

    fs.readdir(path[, options], callback) 例: "use strict"; const fs = require("fs"); ...