欢迎大家访问我的老师的OJ———caioj.cn欢迎大家访问我的老师的OJ———caioj.cn
题面描述
思路
快去%PoPoQQQ
AC code
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define gc getchar()
using namespace std;
const int mod=20101009;
const int N=1e7+10;
int pr,prime[N],mu[N],s[N];bool v[N];
ll ans,n,m;
ll sum(ll x,ll y)
{
return (((x*(x+1)/2)%mod)*((y*(y+1)/2)%mod))%mod;
}
void pre()
{
mu[1]=1;pr=0;ll t=min(n,m);
for(int i=2;i<=t;i++)
{
if(!v[i])mu[i]=-1,prime[++pr]=i;
for(int j=1;j<=pr&&prime[j]*i<=t;j++)
{
v[i*prime[j]]=1;
if(i%prime[j]==0){mu[i*prime[j]]=0;break;}
mu[i*prime[j]]=-mu[i];
}
}
for(ll i=1;i<=t;i++)
s[i]=(s[i-1]+(i*i*mu[i])%mod)%mod;
}
ll F(ll x,ll y)
{
ll ans=0,last;
for(ll i=1;i<=min(x,y);i=last+1)
{
last=min(x/(x/i),y/(y/i));
ans=(ans+(s[last]-s[i-1])*sum(x/i,y/i)%mod)%mod;
}
return ans;
}
int main()
{
scanf("%lld%lld",&n,&m);
pre();
ll last;
for(ll d=1;d<=min(n,m);d=last+1)
{
last=min(n/(n/d),m/(m/d));
ans=(ans+(d+last)*(last-d+1)/2%mod*F(n/d,m/d)%mod)%mod;
}
printf("%lld\n",(ans+mod)%mod);
return 0;
}