题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5895

f(n)=f(n-2)+2*f(n-1)
f(n)*f(n-1)=f(n-2)*f(n-1)+2*f(n-1)*f(n-1);
2*f(n-1)*f(n-1)=f(n)*f(n-1)-f(n-2)*f(n-1);
累加可得 g(n) = f(n)*f(n+1)/2
 
然后这个公式:A^x % m = A^(x%phi(m)+phi(m)) % m (x >= phi(m))
 
反正比赛没做出来.
#include <bits/stdc++.h>
#define LL long long
using namespace std;
struct Maxtri{
LL v[][];
Maxtri(){memset(v,,sizeof(v));}
}ori;
LL n, y, x, s, mod ;
Maxtri mult(Maxtri a,Maxtri b){
Maxtri temp;
for(int i=;i<;i++){
for(int j=;j<;j++){
for(int k=;k<;k++){
temp.v[i][j] = (temp.v[i][j]+(a.v[i][k]*b.v[k][j])%mod)%mod;
}
}
}
return temp;
}
LL pow_mod(Maxtri a,LL n){
if(n==) return ;
if(n==) return ;
if(n==) return ;
n-=;
Maxtri ans;
for(int i=;i<;i++){
ans.v[i][i] = ;
}
while(n){
if(n&) ans = mult(ans,a);
a = mult(a,a);
n>>=;
}
return (ans.v[][]*+ans.v[][])%mod;
}
LL pow_mod1(LL a,LL n,LL mod){
LL ans = ;
while(n){
if(n&) ans = ans*a%mod;
a = a*a%mod;
n>>=;
}
return ans;
}
LL Phi(LL x)
{
LL ans = x;
for(LL i=2LL; i*i<=x; i++)
{
if(x % i == )
{
ans -= ans/i;
while(x % i == )
x /= i;
}
}
if(x > )
ans -= ans/x;
return ans;
}
int main(){
ori.v[][] = ,ori.v[][] = ;
ori.v[][] = ,ori.v[][] = ;
int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%lld%lld%lld%lld",&n, &y, &x, &s);
s++;
LL phi = *Phi(s);
mod = *phi;
LL fn = pow_mod(ori,n*y);
LL fn1 = pow_mod(ori,n*y+);
LL ans = ((fn*fn1)%mod/);
ans+=phi;
printf("%lld\n",pow_mod1(x,ans,s)%s);
}
return ;
}

hdu 5895(矩阵快速幂+欧拉函数)的更多相关文章

  1. HDU 3221 矩阵快速幂+欧拉函数+降幂公式降幂

    装载自:http://www.cnblogs.com/183zyz/archive/2012/05/11/2495401.html 题目让求一个函数调用了多少次.公式比较好推.f[n] = f[n-1 ...

  2. HDU4549 M斐波那契数列 矩阵快速幂+欧拉函数+欧拉定理

    M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  3. [bzoj 1409] Password 矩阵快速幂+欧拉函数

    考试的时候想到了矩阵快速幂+快速幂,但是忘(bu)了(hui)欧拉定理. 然后gg了35分. 题目显而易见,让求一个数的幂,幂是斐波那契数列里的一项,考虑到斐波那契也很大,所以我们就需要欧拉定理了 p ...

  4. HDU 4549 矩阵快速幂+快速幂+欧拉函数

    M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  5. Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)

    传送门 题目 \[ \begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{aligned} \] 思路 我们通过迭代发 ...

  6. hdu4549 矩阵快速幂 + 欧拉降幂

    R - M斐波那契数列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  ...

  7. Super A^B mod C (快速幂+欧拉函数+欧拉定理)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 题目:Problem Description Given A,B,C, You should quick ...

  8. hdu 2814 快速求欧拉函数

    /** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include & ...

  9. hdu 2824 The Euler function(欧拉函数)

    题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...

随机推荐

  1. Linux内核设计第三周学习总结 跟踪分析Linux内核的启动过程

    陈巧然 原创作品 转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 实验步骤 登陆实验楼虚 ...

  2. php扩展库 说明

    1 zlib是提供数据压缩用的函式库, 2 libxml2 Libxml2 is the XML C parser and toolkit developed for the Gnome projec ...

  3. Windows服务器下用IIS Rewrite组件为IIS设置伪静态方法

      1.将下载的IIS Rewrite 组件解压,放到适当的目录(如 C:Rewrite)下,IIS Rewrite 组件下载 http://www.helicontech.com/download- ...

  4. Java Socket UDP编程

    package com; import java.io.IOException; import java.net.*; /** * UDP Client * * Created by Administ ...

  5. array_diff、array_diff_key、array_diff_ukey、array_diff_assoc、array_diff_uassoc 的用法

    <?php // array_diff* 系列的函数都返回关联数组// array_diff* 系列函数返回数组的差集(返回在第一个参数中, 但不在其他参数中的元素) $array1 = [ ' ...

  6. 14.Android UiAutomator 图像处理

    一.BitMap介绍 1.图像使用场景 1)效果类截图 2)不可见的组件图像对比 3)失败与异常截图 4)利用图像判断组件 2.部分API简单说明 API 说明 compress 压缩图片 copy ...

  7. 通过ida dump Uinity3D的加密dll

    声明: 1.本文转载自:http://www.52pojie.cn/thread-398266-1-1.html,仅供自己保存使用,高手勿喷 2.欢迎学习交流 通过ida dump Uinity3D的 ...

  8. Linux常用网络工具:批量主机服务扫描之netcat

    netcat又叫做瑞士军刀,是黑客和系统管理员常用的网络工具,最初开发的目的是文件传输,后来发展出很多强大的功能,比如也可以完成批量主机服务扫描. 之前介绍了另一个更常用的批量主机服务扫描工具:nma ...

  9. linux 文件IO

    1.文件描述符 (1)文件描述符的本质是一个数字,这个数字本质上是进程表中文件描述符表的一个表项,进程通过文件描述符作为index去索引查表得到文件表指针,再间接访问得到这个文件对应的文件表.(2)文 ...

  10. jeecms上传文件限制导致413-Request Entity Too Large

    1:spring mvc 上传限制大小  配置是否允许在上传文件的大小 <bean id="multipartResolver" class="org.spring ...