# 【[国家集训队]Crash的数字表格 / JZPTAB】

$\sum_{i=1}^N\sum_{j=1}^Mlcm(i,j)$

$\sum_{i=1}^N\sum_{j=1}^M\frac{i\times j}{(i,j)}$

$f(n)=\sum_{i=1}^N\sum_{j=1}^M[(i,j)==n]\times i\times j$

$F(n)=\sum_{i=1}^N\sum_{j=1}^M[n|(i,j)]\times i\times j$

$=\frac{n\times(\left \lfloor \frac{N}{n}\right \rfloor+1)\times \left \lfloor \frac{N}{n} \right \rfloor}{2}\times\frac{n\times(\left \lfloor \frac{M}{n}\right \rfloor+1)\times \left \lfloor \frac{M}{n} \right \rfloor}{2}$

$F(n)=\sum_{n|d}f(d)$

$f(n)=\sum_{n|d}\mu(\frac{d}{n})F(d)$

$Ans=\sum_{i=1}^N\frac{f(i)}{i}$

$=\sum_{i=1}^N\times\frac{1}{i}\sum_{i|d}\mu(\frac{d}{i})\frac{d\times(\left \lfloor \frac{N}{d}\right \rfloor+1)\times \left \lfloor \frac{N}{d} \right \rfloor}{2}\times\frac{d\times(\left \lfloor \frac{M}{d}\right \rfloor+1)\times \left \lfloor \frac{M}{d} \right \rfloor}{2}$

$Ans=\sum_{d=1}^N\frac{(\left \lfloor \frac{N}{d}\right \rfloor+1)\times \left \lfloor \frac{N}{d} \right \rfloor\times(\left \lfloor \frac{M}{d}\right \rfloor+1)\times \left \lfloor \frac{M}{d} \right \rfloor}{4}\sum_{i|d}\frac{\mu(\frac{d}{i})\times d^2}{i}$


#include<iostream>
#include<cstring>
#include<cstdio>
#define re register
#define maxn 10000005
#define LL long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
const LL mod=20101009;
int n,m;
int f[maxn],p[maxn>>2];
LL pre[maxn];
int main()
{
scanf("%d%d",&n,&m);
if(n>m) std::swap(n,m);
f[1]=pre[1]=1;
for(re int i=2;i<=n;i++)
{
if(!f[i]) p[++p[0]]=i,pre[i]=(1-i+mod);
for(re int j=1;j<=p[0]&&p[j]*i<=n;j++)
{
f[p[j]*i]=1;
if(i%p[j]==0)
{
pre[i*p[j]]=pre[i];
break;
}
pre[p[j]*i]=pre[p[j]]*pre[i]%mod;
}
}
for(re int i=1;i<=n;i++) pre[i]=(i*pre[i]%mod+pre[i-1])%mod;
LL ans=0;
for(re LL l=1,r;l<=n;l=r+1)
{
r=min(n/(n/l),m/(m/l));
LL N=n/l,M=m/l;
ans=(ans+((N+1)*N/2%mod)*((M+1)*M/2%mod)%mod*(pre[r]-pre[l-1]+mod)%mod)%mod;
}
printf("%lld\n",ans);
return 0;
}



$\sum_{i|d}\frac{\mu(\frac{d}{i})\times d^2}{i}=d\times\sum_{T|d}\mu(T)\times T$

$h(p[j]*i)=h(i)$

$Ans=\sum_{d=1}^N\frac{(\left \lfloor \frac{N}{d}\right \rfloor+1)\times \left \lfloor \frac{N}{d} \right \rfloor\times(\left \lfloor \frac{M}{d}\right \rfloor+1)\times \left \lfloor \frac{M}{d} \right \rfloor}{4}\times d\times h(d)$


#include<iostream>
#include<cstring>
#include<cstdio>
#define re register
#define maxn 10000005
#define LL long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
const LL mod=20101009;
int n,m;
int f[maxn],p[maxn>>2];
LL pre[maxn];
int main()
{
scanf("%d%d",&n,&m);
if(n>m) std::swap(n,m);
f[1]=pre[1]=1;
for(re int i=2;i<=n;i++)
{
if(!f[i]) p[++p[0]]=i,pre[i]=(1-i+mod);
for(re int j=1;j<=p[0]&&p[j]*i<=n;j++)
{
f[p[j]*i]=1;
if(i%p[j]==0)
{
pre[i*p[j]]=pre[i];
break;
}
pre[p[j]*i]=pre[p[j]]*pre[i];
}
}
for(re int i=1;i<=n;i++) pre[i]=(i*pre[i]%mod+pre[i-1])%mod;
LL ans=0;
for(re LL l=1,r;l<=n;l=r+1)
{
r=min(n/(n/l),m/(m/l));
LL N=n/l,M=m/l;
ans=(ans+((N+1)*N/2%mod)*((M+1)*M/2%mod)%mod*(pre[r]-pre[l-1]+mod)%mod)%mod;
}
printf("%lld\n",ans);
return 0;
}


【[国家集训队]Crash的数字表格 / JZPTAB】

(0)
(0)

© 2014 mamicode.com 版权所有 京ICP备13008772号-2