Declare:
k=∑ m i=1 φ(i∗n) mod 1000000007 k=∑i=1mφ(i∗n) mod 1000000007

n n

is a square-free number.

φ φ

is the Euler's totient function.

find:
ans=k k k k ... k      mod p ans=kkkk...k mod p

There are infinite number of k k

InputMultiple test cases(test cases ≤100 ≤100

), one line per case.

Each line contains three integers, n,m n,m

and p p

.

1≤n,m,p≤10 7  1≤n,m,p≤107

OutputFor each case, output a single line with one integer, ans.Sample Input

1 2 6
1 100 9

Sample Output

4
7

题意:k=∑ φ(i∗n)%1000000007;求K^(K^(K^....))%P;

思路:第二部分用欧拉降幂一层一层的降。第一部分可以看这里。

就是左边部分 φ(p)=p-1,但是有的部分由于没有i含有p因数,实际是p而不是p-1,所以要把这部分加进去,所以就有了右边部分。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=;
int phi[maxn],p[maxn],vis[maxn],cnt;
vector<int>G[maxn];
void prime()
{
phi[]=; for(int i=;i<maxn;i++){
if(!vis[i]) p[++cnt]=i,phi[i]=i-;
for(int j=;j<=cnt&&p[j]*i<maxn;j++){
vis[p[j]*i]=; phi[i*p[j]]=phi[i]*phi[p[j]];
if(i%p[j]==){ phi[i*p[j]]=phi[i]*p[j]; break;}
}
}
}
int qpow(int a,int x,int P){
int res=; while(x){
if(x&) res=(ll)res*a%P;
a=(ll)a*a%P; x>>=;
} return res;
}
int get(int K,int P)
{
if(P==) return ;
return qpow(K,get(K,phi[P])+phi[P],P);
}
int main()
{
prime();
int P,ans,T;
scanf("%d",&T);
while(T--){
scanf("%d",&P);
ans=get(,P);
printf("%d\n",ans);
}
return ;
}

HDU - 5728:PowMod (欧拉函数&指数循环节)的更多相关文章

  1. HDU 2824 简单欧拉函数

    1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...

  2. HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. HDU 2588 GCD (欧拉函数)

    GCD Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status De ...

  4. HDU 1695 GCD 欧拉函数+容斥定理

    输入a b c d k求有多少对x y 使得x在a-b区间 y在c-d区间 gcd(x, y) = k 此外a和c一定是1 由于gcd(x, y) == k 将b和d都除以k 题目转化为1到b/k 和 ...

  5. hdu 6434 Count (欧拉函数)

    题目链接 Problem Description Multiple query, for each n, you need to get $$$$$$ \sum_{i=1}^{n} \sum_{j=1 ...

  6. HDU 1695 GCD (欧拉函数,容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  7. hdu 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. Problem I. Count - HDU - 6434(欧拉函数)

    题意 给一个\(n\),计算 \[\sum_{i=1}^{n}\sum_{j=1}^{i-1}[gcd(i + j, i - j) = 1]\] 题解 令\(a = i - j\) 要求 \[\sum ...

  9. HDU 3501【欧拉函数拓展】

    欧拉函数 欧拉函数是指:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) . 通式:φ(x)=x*(1-1/p1)(1-1/p2)(1-1/p3)*(1-1/p4)-..(1- ...

  10. GuGuFishtion HDU - 6390 (欧拉函数,容斥)

    GuGuFishtion \[ Time Limit: 1500 ms\quad Memory Limit: 65536 kB \] 题意 给出定义\(Gu(a, b) = \frac{\phi(ab ...

随机推荐

  1. toLatin1 toLocal8Bit

    toLatin1.toLocal8Bit都是QString转QByteArray的方法,Latin1代表ASCII,Local8Bit代表unicode

  2. 单片机、嵌入式CAN通信原理

    工作原理: 单片机里内置了一个FIFO(先进先出)芯片,需要发送什么报文,就往这个芯片里写.比如有两个单片机作为CAN节点,A节点往自己的FIFO中写CAN报文,B节点往自己的FIFO中写CAN报文. ...

  3. sublime text3配置ctrl+鼠标左键进行函数跳转【转】

    本文转载自:https://blog.csdn.net/shangdibaozi/article/details/77503426 点击Preferences->Browse Packages进 ...

  4. SpringBoot @Annotation

    Annotation简介 Annotation是JDK1.5引入的特性,包含在java.lang.annotation包中. 它是附加在代码中的一些元信息,将一个类的外部信息与内部成员联系起来,在 编 ...

  5. HDU 1241 油田

    这道题明明很简单但不知道为什么运行结果一直错,但提交却是对的!代码真是神奇,不过我猜测可能是提上给出的数据错了,可能提上给的数据m和n后多给了一个空格或回车,但题的数据没有 #include<s ...

  6. spring security采用自定义登录页和退出功能

    更新... 首先采用的是XML配置方式,请先查看  初识Spring security-添加security 在之前的示例中进行代码修改 项目结构如下: 一.修改spring-security.xml ...

  7. Luogu-3250 [HNOI2016]网络

    Luogu-3250 [HNOI2016]网络 题面 Luogu-3250 题解 CDQ分治...这个应该算是整体二分吧 二分重要度,按照时间从小到大加入大于重要度的边 对于一个询问,如果经过这个点的 ...

  8. MapReduce job在JobTracker初始化源码级分析

    mapreduce job提交流程源码级分析(三)中已经说明用户最终调用JobTracker.submitJob方法来向JobTracker提交作业.而这个方法的核心提交方法是JobTracker.a ...

  9. LeetCode第[17]题(Java):Letter Combinations of a Phone Number

    题目:最长公共前缀 难度:EASY 题目内容: Given a string containing digits from 2-9 inclusive, return all possible let ...

  10. 处理跨线程操作问题(使用Action和delegate或lambda表达式)

    方法A: Action f = () =>                    {                       txtProcess.Text = "开始更新程序.. ...