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 ...
随机推荐
- ES集群重启
操作步骤: 1. Disable shard allocation curl -XPUT 'localhost:9200/_cluster/settings?pretty' -d '{ " ...
- make cmake catkin_make
在Linux下进行C语言编程,必然要采用GNU GCC来编译C源代码生成可执行程序. 一.GCC快速入门 Gcc指令的一般格式为:Gcc [选项] 要编译的文件 [选项] [目标文件] 其中,目标文件 ...
- Django 中间件简介
Django 中间件简介 django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后,django会根据自己的规则在合适的时机执行中间件中相应的方法. ...
- MySQL-5.7 DELETE语句详解
1.语法 (1)单表 DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name [PARTITION (partition_name [, partit ...
- React Native 常用学习链接地址
Android Studio下载http://www.android-studio.org/ 第二章:Android Studio概述(一)http://ask.android-studio.org/ ...
- springboot--配置文件加载顺序
-file:./config(内部配置) -file:./ (内部配置) -classpath:/config (外部配置) -classpath:/ (外部配置) 运维: spring -jar s ...
- Cnblog页面美化小记
Cnblog页面美化小记 这两天我在网上翻找了许许多多的资料,打开了不计其数的博客,对着\(js\).\(html\).\(css\)等文件删删改改,在浏览器和\(vscode\)间辗转腾挪...总算 ...
- linux 基本命令___0003 字符串处理和yum安装软件的路径
字符串变量的处理 参考链接:SHELL字符串处理技巧 计算字符串的字符数量: ${#str} str="xxx-Lane1_S2_L001_R1_trim.fastq" echo ...
- cmd常用命令大全
cmd命令提示符:只是系统模拟的dos操作环境,且功能远远大于dos 1. 返回上一层 cd.. 2. 进入A文件夹 cd A 3. 进入A文件夹下的B文件夹 cd A/B 4. c盘下的A文 ...
- 死循环的/etc/profile
用户服务器登陆后停在以下界面 Connecting to ... Connection established. To escape to local shell, press 'Ctrl+Alt+] ...