hdu 5895(矩阵快速幂+欧拉函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5895
#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(矩阵快速幂+欧拉函数)的更多相关文章
- HDU 3221 矩阵快速幂+欧拉函数+降幂公式降幂
装载自:http://www.cnblogs.com/183zyz/archive/2012/05/11/2495401.html 题目让求一个函数调用了多少次.公式比较好推.f[n] = f[n-1 ...
- HDU4549 M斐波那契数列 矩阵快速幂+欧拉函数+欧拉定理
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- [bzoj 1409] Password 矩阵快速幂+欧拉函数
考试的时候想到了矩阵快速幂+快速幂,但是忘(bu)了(hui)欧拉定理. 然后gg了35分. 题目显而易见,让求一个数的幂,幂是斐波那契数列里的一项,考虑到斐波那契也很大,所以我们就需要欧拉定理了 p ...
- HDU 4549 矩阵快速幂+快速幂+欧拉函数
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- 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} \] 思路 我们通过迭代发 ...
- hdu4549 矩阵快速幂 + 欧拉降幂
R - M斐波那契数列 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- Super A^B mod C (快速幂+欧拉函数+欧拉定理)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 题目:Problem Description Given A,B,C, You should quick ...
- hdu 2814 快速求欧拉函数
/** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include & ...
- hdu 2824 The Euler function(欧拉函数)
题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...
随机推荐
- 20135239益西拉姆 Linux内核分析 汇编一个简单的c程序并分析其指令过程
益西拉姆+<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 第一周linux内核分析 学习笔记 一.计算机 ...
- 【linux】/dev/null与/dev/zero详解
引用别人的资源,收藏: http://www.cnblogs.com/xianghang123/archive/2012/03/23/2413381.html
- Square Country
原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1073 分析:dp,dp[i]表示钱为i且恰好用完时能买的最少土地数,易知dp[i]=mi ...
- bzoj1467 Pku3243 clever Y
1467: Pku3243 clever Y Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 313 Solved: 181[Submit][Status ...
- 洛谷P1445 [Violet] 樱花 (数学)
洛谷P1445 [Violet] 樱花 题目背景 我很愤怒 题目描述 求方程 1/X+1/Y=1/(N!) 的正整数解的组数,其中N≤10^6. 解的组数,应模1e9+7. 输入输出格式 输入格式: ...
- Intellj IDEA使用技巧记录
▲.Intellj IDEA光标变成了insert光标状态 且不能编辑操作: https://blog.csdn.net/aosica321/article/details/52787418 ▲.在i ...
- 洛谷 2186 小Z的栈函数
https://www.luogu.org/problem/show?pid=2186 题目描述 小Z最近发现了一个神奇的机器,这个机器的所有操作都是通过维护一个栈来完成的,它支持如下11个操作: N ...
- python 文字转语音包pyttsx安装出错解决方法
pyttsx的python的文字转语音的包,但是pyttsx的官方网站上资源只更新2012年,所以在py3中使用pip install pyttsx或者下载安装包进行安装时,虽然可以安装成功,但是im ...
- 正则表达式:Python 模块 re 简介
为了使文章更具可读性,本文将正则表达式冗长的 语法介绍 放在了文章的末尾. 一.正则表达式简介 正则表达式(RegExp)是一种文本模式,包括普通字符(例如,a 到 z 之间的字母)和特殊字符(元字符 ...
- 2017ACM暑期多校联合训练 - Team 2 1001 HDU 6045 Is Derek lying? (模拟)
题目链接 Problem Description Derek and Alfia are good friends.Derek is Chinese,and Alfia is Austrian.Thi ...