题目:
题目链接:
题解:
莫比乌斯反演
#include <bits/stdc++.h>
using namespace std;
long long mod=20101009;
const int N=1e7+10;
long long mu[N],pri[N],con,sum[N];
bool st[N];
long long n,m;
void getmus()
{
mu[1]=1;
for(int i=2;i<=N;i++)
{
if(!st[i])
{
pri[++con]=i;
mu[i]=-1;
}
for(int j=1;i*pri[j]<=N;j++)
{
int t=pri[j]*i;
st[t]=1;
if(i%pri[j]==0) break;
mu[t]=-mu[i];
}
}
for(int i=1;i<=N;i++) sum[i]=(sum[i-1]+1ll*i*i%mod*(mu[i]+mod)%mod)%mod;
}
int suma(int x,int y)
{
return (1ll*(x+1)*x/2%mod)*(1ll*(y+1)*y/2%mod)%mod;
}
long long solve(int x,int y)
{
long long ans=0;
int a=min(x,y);
for(int i=1,r;i<=a;i=r+1)
{
r=min(x/(x/i),y/(y/i));
ans=(ans+1ll*(sum[r]-sum[i-1]+mod)%mod*suma(x/i,y/i)%mod)%mod;
}
return ans;
}
int main()
{
getmus();
cin>>n>>m;
long long x=min(n,m);
long long ans=0;
for(int i=1,r=1;i<=x;i=r+1)
{
r=min(n/(n/i),m/(m/i));
ans=(ans+1ll*(r-i+1)*(r+i)/2%mod*solve(n/i,m/i)%mod)%mod;
}
cout<<ans<<endl;
return 0;
}