Pushing the persimmon, the answer is this East (I am not familiar with Mobius inversion, indeed QAQ)
∑d=1ndd∑x=1⌊nd⌋μ(x)⋅x2d∑i=1⌊ndx⌋id∑j=1⌊mdx⌋jd\sum_{d=1}^n d^d \sum_{x=1}^{\lfloor \frac{n}{d} \rfloor} \mu(x) \cdot x^{2d} \sum_{i=1}^{\lfloor \frac{n}{dx} \rfloor} i^d \sum_{j=1}^{\lfloor \frac{m}{dx} \rfloor} j^dd=1∑nddx=1∑⌊dn⌋μ(x)⋅x2di=1∑⌊dxn⌋idj=1∑⌊dxm⌋jd
(So tired, this persimmon is so complicated that I don't write any more.)
Then the violence asks you to take a little care of the two things behind it, O(nlogn)O(nlogn)O(nlogn).
After the initial pre-processing, there are two more log s for the direct and fast power of the next two items. As a belief player, the result is handed in directly T and QAQ
//#pragma GCC optimize(2) //#pragma GCC optimize(3) #include<bits/stdc++.h> #include<tr1/unordered_map> #define LL long long #define re register #define fr(i,x,y) for(re int i=(x),z=y;i<=z;i++) #define rf(i,x,y) for(int i=(x);i>=(y);i--) #define frl(i,x,y) for(int i=(x);i<(y);i++) using namespace std; using namespace tr1; const int N=500005; const int INF=2147483647; const int p=1e9+7; int n,m; int mu[N],b[N],L,pri[N]; void read(int &x){ char ch=getchar();x=0; for(;ch<'0'||ch>'9';ch=getchar()); for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0'; } inline void Add(LL &x,LL y){ x+=y; while(x<0) x+=p; while(x>=p) x-=p; } inline LL qpow(LL a,int n){ LL ans=1; for(LL sum=a;n;n>>=1,sum=sum*sum%p) if (n&1) ans=ans*sum%p; return ans; } void init(){ mu[1]=1; frl(i,2,N){ if (!b[i]) pri[++L]=i,mu[i]=-1; for(int j=1;j<=L&&i*pri[j]<N;j++){ b[i*pri[j]]=1; if (i%pri[j]==0){ mu[i*pri[j]]=0; break; } mu[i*pri[j]]=-mu[i]; } } } LL sum[N],pw[N]; int main(){ init(); read(n);read(m); if (n>m) swap(n,m); LL ans=0; fr(i,1,m) pw[i]=1; fr(i,1,n){ //LL sum1=0,sum2=0; fr(j,1,m/i) sum[j]=(sum[j-1]+pw[j]*j%p)%p,pw[j]=pw[j]*j%p; //Add(ans,sum1*sum2%p*qpow(i,i)%p); LL s=0; fr(j,1,n/i) Add(s,mu[j]*qpow(sum[j]-sum[j-1],2)%p*sum[n/i/j]%p*sum[m/i/j]%p); Add(ans,s*qpow(i,i)%p); } cout<<ans<<endl; return 0; }