![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define mod 1000000007 4 #define N 500005 5 #define ll long long 6 ll n,m,t,ans,mu[N],vis[N],p[N],c[N],sum[N]; 7 void xxs(int n){ 8 mu[1]=1; 9 for(int i=2;i<=n;i++){ 10 if (!vis[i])mu[p[++p[0]]=i]=-1; 11 for(int j=1;(j<=p[0])&&(i*p[j]<=n);j++){ 12 vis[i*p[j]]=1; 13 if (i%p[j]==0)break; 14 mu[i*p[j]]=-mu[i]; 15 } 16 } 17 } 18 ll ksm(ll n,ll m){ 19 if (!m)return 1LL; 20 ll s=ksm(n,m>>1); 21 s=s*s%mod; 22 if (m&1)s=s*n%mod; 23 return s; 24 } 25 int main(){ 26 xxs(N-5); 27 scanf("%lld%lld", &n,&m); 28 if (n<m)swap(n,m); 29 for(int i=1;i<=n;i++)c[i]=1; 30 for(int i=1;i<=m;i++){ 31 for(int j=1;i*j<=n;j++){ 32 c[j]=c[j]*j%mod; 33 sum[j]=(sum[j-1]+c[j])%mod; 34 } 35 t=ksm(i,i); 36 for(int j=1;i*j<=m;j++)ans=(ans+t*mu[j]%mod*c[j]%mod*c[j]%mod*sum[n/(i*j)]%mod*sum[m/(i*j)])%mod; 37 } 38 printf("%lld",ans); 39 }