题目
题目大意就是求 ∑ni=1∑mj=1lcm(i,j) .
分析:
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 10000000
#define MOD 20101009
#define Sum(x,y) (1ll*x*(x+1)/2%MOD*(1ll*y*(y+1)/2%MOD)%MOD)
int mu[MAXN+10],p[MAXN+10],pcnt,sum[MAXN+10],n,m,ans;
bool f[MAXN+10];
void prepare(){
int i,j,t=min(n,m);
mu[1]=sum[1]=1;
for(i=2;i<=t;i++){
if(!f[i])
p[++pcnt]=i,mu[i]=-1;
for(j=1;p[j]*i<=t;j++){
f[i*p[j]]=1;
if(i%p[j]==0){
mu[i*p[j]]=0;
break;
}
mu[i*p[j]]=-mu[i];
}
sum[i]=(sum[i-1]+1ll*i*i*mu[i])%MOD;
}
}
void Read(int &x){
char c;
while(c=getchar(),~c)
if(c>='0'&&c<='9'){
x=c-'0';
while(c=getchar(),c>='0'&&c<='9')
x=x*10+c-'0';
ungetc(c,stdin);
return;
}
}
int calf(int n,int m){
int t=min(n,m),i,last,ret=0;
for(i=1;i<=t;i=last+1){
last=min(n/(n/i),m/(m/i));
ret=(ret+((sum[last]-sum[i-1])%MOD*Sum(n/i,m/i))%MOD+MOD)%MOD; } return ret; } void solve(){ int t=min(n,m),i,last; for(i=1;i<=t;i=last+1){ last=min(n/(n/i),m/(m/i));
ans=(ans+1ll*(i+last)*(last-i+1)/2%MOD*calf(n/i,m/i))%MOD; } } int main() { Read(n),Read(m); prepare(); solve(); printf("%d\n",ans); }