HDU - 5728:PowMod (欧拉函数&指数循环节)
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 (欧拉函数&指数循环节)的更多相关文章
- HDU 2824 简单欧拉函数
1.HDU 2824 The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2588 GCD (欧拉函数)
GCD Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status De ...
- 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 和 ...
- hdu 6434 Count (欧拉函数)
题目链接 Problem Description Multiple query, for each n, you need to get $$$$$$ \sum_{i=1}^{n} \sum_{j=1 ...
- HDU 1695 GCD (欧拉函数,容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- hdu 1695 GCD (欧拉函数+容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 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 ...
- HDU 3501【欧拉函数拓展】
欧拉函数 欧拉函数是指:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) . 通式:φ(x)=x*(1-1/p1)(1-1/p2)(1-1/p3)*(1-1/p4)-..(1- ...
- GuGuFishtion HDU - 6390 (欧拉函数,容斥)
GuGuFishtion \[ Time Limit: 1500 ms\quad Memory Limit: 65536 kB \] 题意 给出定义\(Gu(a, b) = \frac{\phi(ab ...
随机推荐
- LeetCode: Next Greater Element I
stack和map用好就行 public class Solution { public int[] nextGreaterElement(int[] findNums, int[] nums) { ...
- java中最常用jar包的用途
jar包用途 axis.jarSOAP引擎包commons-discovery-0.2.jar用来发现.查找和实现可插入式接口,提供一些一般类实例化.单件的生命周期管理的常用方法.jaxrpc.jar ...
- [翻译]PostCSS简介
许多开发人员花时间在使用CSS的预处理器上如less,sass和stylus.这些工具已经成为Web开发的重要组成部分.写一个网站的样式,不使用嵌套,变量或混入等功能很少见.它们每个都是非常实用的,让 ...
- 《Maven实战》第5章 坐标和依赖
5.1 Maven坐标——项目唯一标识 groupId(必须定义):定义Mavan项目隶属的实际项目,如SpringFramework,一个实际项目可包含多个Maven项目 artifactId(必须 ...
- Effective C++ 条款05:了解C++编写并调用哪些函数
规则一 编译器默认操作 // 你认为 class Empty { }; // 实际上 class Empty { public: Empty() { ... } // default 构造函数 Emp ...
- 2.scala控制结构、函数、异常处理
2.scala控制结构.函数.异常处理---小书匠,在线编辑器,MARKDOWN,Evernote,文件版本 a:focus { outline: thin dotted #333; outline: ...
- sql server 2014 在windows server 2012 上安装Analysis Services
Analysis Services Account Name : NT AUTHORITY\SYSTEM
- 在eclipse下使用maven的配置
1 2 3 4 5 6 7 8 public class Shifty { public static void main(String[] args) { int i = 0 ...
- Element UI 框架搭建
Element UI 框架搭建 1.webpack 全局安装 npm install -g webpack 2.淘宝镜像cnpm安装 npm install -g cnpm --registry=ht ...
- bootstrap-datepicker 时间范围选择函数封装
bootstrap-datepicker 时间范围选择函数封装 官网 https://bootstrap-datepicker.readthedocs.io/en/latest/index.html ...