# bzoj 3561

$\sum_{d=1}^{n}\sum_{i=1}^{\frac{n}{d}}\sum_{j=1}^{\frac{m}{d}}[gcd(i,j)\equiv 1](ijd)^{d}$

$\sum_{d=1}^{n}d^{d}\sum_{i=1}^{\frac{n}{d}}\sum_{j=1}^{\frac{m}{d}}\sum_{t|gcd(i,j)}\mu(t)(ij)^{d}$

$\sum_{d=1}^{n}d^{d}\sum_{t=1}^{\frac{n}{d}}\mu(t)\sum_{i=1}^{\frac{n}{dt}}\sum_{j=1}^{\frac{m}{dt}}(ijt^{2})^{d}$

（也就是在后面的$ij$乘积这一项中单独考虑$t$的贡献）

$\sum_{d=1}^{n}d^{d}\sum_{t=1}^{\frac{n}{d}}\mu(t)t^{2d}\sum_{i=1}^{\frac{n}{dt}}i^{d}\sum_{j=1}^{\frac{m}{dt}}j^{d}$

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#define ll long long
using namespace std;
const ll mode=1000000007;
int pri[5000005],mu[5000005],used[5000005];
ll S[5000005],mi[5000005];
int cnt=0;
ll pow_mul(ll x,ll y)
{
ll ret=1;
while(y)
{
if(y&1)ret=ret*x%mode;
x=x*x%mode,y>>=1;
}
return ret;
}
void init()
{
mu[1]=1;
for(int i=2;i<=5000000;i++)
{
if(!used[i])pri[++cnt]=i,mu[i]=-1;
for(int j=1;j<=cnt&&i*pri[j]<=5000000;j++)
{
used[i*pri[j]]=1;
if(i%pri[j]==0){mu[i*pri[j]]=0;break;}
mu[i*pri[j]]=-mu[i];
}
}
}
int main()
{
init();
ll n,m;
scanf("%lld%lld",&n,&m);
if(n>m)swap(n,m);
ll ans=0;
for(int i=1;i<=m;i++)mi[i]=1;
for(int i=1;i<=n;i++)
{
ll s=pow_mul(i,i);
S[0]=0;
for(int j=1;j<=m/i;j++)mi[j]=mi[j]*j%mode,S[j]=(S[j-1]+mi[j])%mode;
ll tempc=0;
for(int j=1;j<=n/i;j++)
{
ll temps=(mu[j]*mi[j]*mi[j]%mode+mode)%mode;
tempc=(tempc+temps*S[n/i/j]%mode*S[m/i/j]%mode)%mode;
}
ans=(ans+s*tempc)%mode;
}
printf("%lld\n",ans);
return 0;
}

posted @ 2019-07-08 14:37  lleozhang  Views(68)  Comments(0Edit  收藏
levels of contents