hdu5728PowMod+欧拉函数和+k的无穷次方取膜
2016-07-29 17:39
288 查看
Problem Description
Declare:
k=∑mi=1φ(i∗n)mod1000000007
n is a square-free number.
φ is the Euler’s totient function.
find:
ans=kkkk...k mod p
There are infinite number of k
Input
Multiple test cases(test cases ≤100), one line per case.
Each line contains three integers, n,m and p.
1≤n,m,p≤107
Output
For each case, output a single line with one integer, ans.
Sample Input
1 2 6
1 100 9
Sample Output
4
7
Author
HIT
Source
2016 Multi-University Training Contest 1
证明参考这位菊苣的吧http://blog.csdn.net/wust_zzwh/article/details/51966450
后边那个k的无穷个k的那个参考八中oj3884
http://blog.csdn.net/xtulollipop/article/details/52065860
Declare:
k=∑mi=1φ(i∗n)mod1000000007
n is a square-free number.
φ is the Euler’s totient function.
find:
ans=kkkk...k mod p
There are infinite number of k
Input
Multiple test cases(test cases ≤100), one line per case.
Each line contains three integers, n,m and p.
1≤n,m,p≤107
Output
For each case, output a single line with one integer, ans.
Sample Input
1 2 6
1 100 9
Sample Output
4
7
Author
HIT
Source
2016 Multi-University Training Contest 1
证明参考这位菊苣的吧http://blog.csdn.net/wust_zzwh/article/details/51966450
后边那个k的无穷个k的那个参考八中oj3884
http://blog.csdn.net/xtulollipop/article/details/52065860
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<iostream> #include<map> #include<queue> using namespace std; #define LL long long const int mod=1000000007; const int maxn=10000005; bool check[maxn]; //用于打表记录的中间量 LL sumPhi[maxn]; //前i个的欧拉函数和 int cnt,phi[maxn],prime[maxn]; //素数个数,欧拉表,素数表 //素数表是第几个素数是什么,欧拉表是i的欧拉是phi[i]; void init(){ //素数+欧拉表 phi[1]=1; cnt=0; for(int i=2;i<maxn;i++){ if(!check[i]){ phi[i]=i-1; prime[cnt++]=i; } for(int j=0;j<cnt;j++){ if(i*prime[j]>=maxn)break; check[i*prime[j]]=true; if(i%prime[j]==0){ phi[i*prime[j]]=phi[i]*prime[j]; break; } else{ phi[i*prime[j]]=phi[i]*(prime[j]-1); } } } sumPhi[0]=0; for(int i=1;i<maxn;i++) sumPhi[i]=(sumPhi[i-1]+phi[i])%mod; } LL phiz(int n,int m){ //计算k, if(n==1) return sumPhi[m]; if(m==1) return phi ; if(m<1) return 0; for(int i=0;i<cnt;i++){ if(n%prime[i]==0){ //n的最小质数prime[i] LL temp1=(prime[i]-1)*phiz(n/prime[i],m)%mod; LL temp2=phiz(n,m/prime[i])%mod; return (temp1+temp2)%mod; } } return 0; } LL pow(LL a,LL b,int p){ //快速幂 LL ret=1; a%=p; while(b){ if(b&1) ret=(ret*a)%p; a=(a*a)%p; b/=2; } return ret; } LL powe(LL k,int p){ //k^b%p if(p==1) return 0; LL temp=powe(k,phi[p]); return pow(k,temp+phi[p],p); } int main(){ init(); int n,m,p; while(scanf("%d %d %d",&n,&m,&p)!=EOF){ LL k=phiz(n,m); printf("%I64d\n",powe(k,p)); } return 0; }
相关文章推荐
- div 和span的区别
- HDU 4901 The Romantic Hero (计数DP)
- linux中的rootfs/initrd/ramfs/initramfs
- deep learning 学习资料
- Linux下redis的安装
- POJ 2349 Arctic Network 【最小生成树变形】
- Intent的显示与隐示 权限的添加
- 关于dispatch_semaphore的使用
- ruby gem passenger依赖关系
- EF下 CodeFirst、DBFirst与ModelFirst分析
- openssl加密与模拟CA签证和颁发
- 关于Linux启动时挂载rootfs的几种方式
- oracle 全文检索创建脚本示例
- 【转】Derivation of the Normal Equation for linear regression
- easy_install - pip
- No command 'mmm' found
- 测试_33
- HDU-5773-The All-purpose Zero-最长上升子序列改写
- Qt的QWaitCondition
- MySQL中NULL和空值对比