参考了某大佬的

我们可以根据(s[n-2], a[n-1]^2, a[n-1]*a[n-2], a[n-2]^2) * A = (s[n-1], a[n]^2, a[n]*a[n-1], a[n-1]^2)

能够求出关系矩阵

|1     0      0     0 |
A =   |1   x^2    x     1 |
        |0  2*x*y  y     0 |
        |0   y^2    0     0 |

这样就A了!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long ll;
const ll Mod = 10007;
const int N = 5;
int msize; struct Mat
{
ll mat[N][N];
}; Mat operator *(Mat a, Mat b)
{
Mat c;
memset(c.mat, 0, sizeof(c.mat));
for(int k = 0; k < msize; ++k)
for(int i = 0; i < msize; ++i)
if(a.mat[i][k])
for(int j = 0; j < msize; ++j)
if(b.mat[k][j])
c.mat[i][j] = (a.mat[i][k] * b.mat[k][j] + c.mat[i][j])%Mod;
return c;
} Mat operator ^(Mat a, ll k)
{
Mat c;
memset(c.mat,0,sizeof(c.mat));
for(int i = 0; i < msize; ++i)
c.mat[i][i]=1;
for(; k; k >>= 1)
{
if(k&1) c = c*a;
a = a*a;
}
return c;
} int main()
{
ll n,x,y;
msize = 4;
while(~scanf("%I64d%I64d%I64d",&n,&x,&y))
{
Mat A;
A.mat[0][0] = 1, A.mat[0][1] = 1, A.mat[0][2] = 0, A.mat[0][3] = 0;
A.mat[1][0] = 0, A.mat[1][1] = x*x%Mod, A.mat[1][2] = 2*x*y%Mod, A.mat[1][3] = y*y%Mod;
A.mat[2][0] = 0, A.mat[2][1] = x, A.mat[2][2] = y, A.mat[2][3] = 0;
A.mat[3][0] = 0, A.mat[3][1] = 1, A.mat[3][2] = 0, A.mat[3][3] = 0;
A = A^n;
printf("%I64d\n", (A.mat[0][0] + A.mat[0][1] + A.mat[0][2] + A.mat[0][3])%Mod);
}
return 0;
}

hdu 3306 Another kind of Fibonacci 矩阵快速幂的更多相关文章

  1. HDU 3306 Another kind of Fibonacci(矩阵+ll超时必须用int&输入必须取模&M必须是int类型)

    Another kind of Fibonacci [题目链接]Another kind of Fibonacci [题目类型]矩阵+ll超时必须用int&输入必须取模&M必须是int ...

  2. HDU 1588 Gauss Fibonacci(矩阵快速幂)

    Gauss Fibonacci Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 2855 斐波那契+矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=2855 化简这个公式,多写出几组就会发现规律 d[n]=F[2*n] 后面的任务就是矩阵快速幂拍一个斐波那契模板出 ...

  4. HDU 5950:Recursive sequence(矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:给出 a,b,n,递推出 f(n) = f(n-1) + f(n-2) * 2 + n ^ 4. f ...

  5. poj 3070 Fibonacci (矩阵快速幂乘/模板)

    题意:给你一个n,输出Fibonacci (n)%10000的结果 思路:裸矩阵快速幂乘,直接套模板 代码: #include <cstdio> #include <cstring& ...

  6. poj 3070 Fibonacci 矩阵快速幂

    Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...

  7. HDU 3292 【佩尔方程求解 && 矩阵快速幂】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...

  8. HDU - 4965 Fast Matrix Calculation 【矩阵快速幂】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4965 题意 给出两个矩阵 一个A: n * k 一个B: k * n C = A * B M = (A ...

  9. hdu 4565 So Easy! (共轭构造+矩阵快速幂)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 题目大意: 给出a,b,n,m,求出的值, 解题思路: 因为题目中出现了开根号,和向上取整后求 ...

随机推荐

  1. 【转载】搭建本地yum源:以下是以centos7为例子

    搭建本地yum源:以下是以centos7为例子  1)首先需要安装 createrepo(需要一个可以使用源的机器,可以访问互联网)安装方法可以使用yum安装epel源 1 yum -y instal ...

  2. 攻防世界(四)php_rce

    攻防世界系列:php_rce 1.打开题目 看到这个还是很懵的,点开任意连接都是真实的场景. 2.ThinkPHP5,这里我们需要知道它存在 远程代码执行的漏洞. ?s=index/\think\ap ...

  3. zabbix监控之邮件报警通知

    zabbix官网的操作指南:https://www.zabbix.com/documentation/4.0/zh/manual 首先我们需要创建一个需要被监控的主机,并设置相应的监控项.当监控项收集 ...

  4. 在 Ubuntu 上安装 .NET SDK 或 .NET 运行时

    在wsl Ubuntu 20.04上面安装dotnet链接 https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-ubuntu Ubun ...

  5. 八、.net core(.NET 6)配置读取appsettings文件内容的通用功能

     添加通用读取配置文件功能 在Wsk.Core.Package项目下,新增Microsoft.Extensions.Configuration包: 在启动项目下,设置appsettings.json属 ...

  6. 【Dubbo】SPI

    什么是SPI SPI是JDK内置的一种服务提供发现机制.目前市面上很多框架都用它来做服务的扩展发现.简单的说,它是一种动态替换发现的机制. jdk 实现方式 需要在 classpath 下创建一个目录 ...

  7. [leetcode] 212. 单词搜索 II(Java)

    212. 单词搜索 II 这leetcode的评判机绝对有问题!!同样的代码提交,有时却超时!害得我至少浪费两个小时来寻找更优的答案= =,其实第一次写完的代码就可以过了,靠!!!第207位做出来的 ...

  8. GO学习-(39) 优雅地关机或重启

    优雅地关机或重启 我们编写的Web项目部署之后,经常会因为需要进行配置变更或功能迭代而重启服务,单纯的kill -9 pid的方式会强制关闭进程,这样就会导致服务端当前正在处理的请求失败,那有没有更优 ...

  9. GO语言的JSON03---JSON文件的序列化与反序列化

    package main import ( "encoding/json" "fmt" "os" ) type Human2 struct ...

  10. Python+Selenium学习笔记16 - unittest单元测试框架

    unittest单元测试框架包括 Test Case,  Test Suite, Test Runner, Test Fixture Test Cases 组成Test Suite, Test Run ...