标签:
我们定义
由于
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define P 20101009LL
using namespace std;
long long n,m,tot=0,mu[10000001],pri[700001];
long long pre[10000001],sum[10000001];
bool f[10000001];
long long get(long long n,long long m)
{
long long i,last=0; long long ans=0;
if (n>m) swap(n,m);
for (i=1;i<=n;i=last+1)
{
last=min(n/(n/i),m/(m/i));
ans=(ans+(long long)(((long long)((sum[last]-sum[i-1]+P)%P)*(long long)(((long long)((((m/i)*(m/i+1))/2)%P)*(long long)((((n/i)*(n/i+1))/2)%P))%P)))%P)%P;
if (ans<0) cout<<‘!‘<<endl;
}
return ans;
}
long long work(long long n,long long m)
{
long long i,last=0; long long ans=0;
if (n>m) swap(n,m);
for (i=1;i<=n;i=last+1)
{
last=min(n/(n/i),m/(m/i));
ans=(ans+(long long)((get(n/i,m/i)%P*(long long)((pre[last]-pre[i-1]+P)%P)))%P)%P;
if (ans<0) cout<<‘!‘<<endl;
}
return ans;
}
int main()
{
long long i,j,maxn;
scanf("%I64d%I64d",&n,&m);
mu[1]=1;maxn=max(n,m);
for (i=2;i<=maxn;++i)
{
if (!f[i])
{
mu[i]=-1;
pri[++tot]=i;
}
for (j=1;j<=tot&&i*pri[j]<=maxn;++j)
{
f[i*pri[j]]=true;
if (i%pri[j]==0)
{
mu[i*pri[j]]=0;
break;
}
else mu[i*pri[j]]=-mu[i];
}
}
for (i=1;i<=maxn;++i) {sum[i]=(sum[i-1]+(long long)((i*i)%P*mu[i])%P+P)%P; pre[i]=(long long)(pre[i-1]+i)%P;}
printf("%I64d\n",work(n,m));
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/lcomyn/article/details/47282061