您的位置:首页 > 其它

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

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: