【BZOJ 3560】DZY Loves Math V(欧拉函数)
直接考虑欧拉函数的性质
考虑每个质因数的贡献乘起来
若在中出现次
那么的贡献为
然后就完了
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int mod=1e9+7;
inline int add(int a,int b){return (a+=b)>=mod?(a-mod):a;}
inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
inline int mul(int a,int b){static ll r;r=1ll*a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline void Dec(int &a,int b){a-=b,a+=a>>31&mod;}
inline void Mul(int &a,int b){static ll r;r=1ll*a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
cs int N=10000006,M=1000006;
int pr[M],tot,mnp[N];
vector<int> num[N];
bitset<N> vis;
inline void init(int len=N-6){
for(int i=2;i<=len;i++){
if(!vis[i])pr[++tot]=i,mnp[i]=i;
for(int j=1,p;j<=tot&&i*pr[j]<=len;j++){
p=i*pr[j],vis[p]=1,mnp[p]=pr[j];
if(i%pr[j]==0)break;
}
}
}
int n,pri[100],cnt;
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
init();
n=read();
for(int i=1;i<=n;i++){
int x=read();cnt=0;
while(x>1){pri[++cnt]=mnp[x],x/=mnp[x];}
sort(pri+1,pri+cnt+1);
for(int j=1;j<=cnt;j++){
int c=1;
while(pri[j+1]==pri[j]&&j<cnt)j++,c++;
num[pri[j]].pb(c);
}
}
int ans=1;
for(int i=1;i<=tot;i++)if(num[pr[i]].size()){
int ret=1,p=pr[i];
for(int j=0,iv=Inv(p-1);j<num[p].size();j++){
int b=num[p][j];
Mul(ret,mul(dec(ksm(p,b+1),1),iv));
}
Dec(ret,1);
Mul(ans,add(1,mul(ret,mul(p-1,Inv(p)))));
}
cout<<ans<<'\n';
}