p4980 polya定理
分析
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
const int mod = 1e9+7;
inline int pw(int x,int p){
int res=1;
while(p){
if(p&1)res=res*x%mod;
x=x*x%mod;
p>>=1;
}
return res;
}
inline int phi(int x){
int res=x;
for(int i=2;i*i<=x;i++)
if(x%i==0){
res=res/i*(i-1);
while(x%i==0)x/=i;
}
if(x>1)res=res/x*(x-1);
return res;
}
signed main(){
int t,n,m,i,j,k,Ans;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
Ans=0;
for(i=1;i*i<=n;i++)
if(n%i==0){
Ans=(Ans+pw(n,i)*phi(n/i)%mod)%mod;
if(i*i!=n)Ans=(Ans+pw(n,n/i)*phi(i)%mod)%mod;
}
cout<<Ans*pw(n,mod-2)%mod<<endl;
}
return 0;
}