【BZOJ 3561】 DZY Loves Math VI(莫比乌斯反演)
考虑有
然后枚举
令简单莫反得到
设
然后做就完了
复杂度是调和级数的
#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);}
inline int fix(int x){return (x<0)?x+mod:x;}
cs int N=500005;
int pr[N],mu[N],tot;
bitset<N> vis;
inline void init(cs int len=N-5){
mu[1]=1;
for(int i=2;i<=len;i++){
if(!vis[i])pr[++tot]=i,mu[i]=mod-1;
for(int j=1;j<=tot&&i*pr[j]<=len;j++){
vis[i*pr[j]]=1;
if(i%pr[j]==0)break;
mu[i*pr[j]]=mod-mu[i];
}
}
}
int n,m,f[N],s[N];
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
init();
n=read(),m=read();
if(n<m)swap(n,m);
for(int i=1;i<=n;i++)f[i]=1;
int ans=0;
for(int d=1;d<=m;d++){
int ln=n/d,lm=m/d,ret=0;
for(int i=1;i<=ln;i++)Mul(f[i],i),s[i]=add(s[i-1],f[i]);
for(int k=1;k<=lm;k++)
Add(ret,mul(mul(s[ln/k],s[lm/k]),mul(mu[k],mul(f[k],f[k]))));
Add(ans,mul(ret,ksm(d,d)));
}
cout<<ans<<'\n';
}