# ●BZOJ 2693 jzptab

http://www.lydsy.com/JudgeOnline/problem.php?id=2693

$ANS=\sum_{g=1}^{min(n,m)}g\times \sum_{d=1}^{min(\lfloor \frac{n}{g} \rfloor,\lfloor \frac{m}{g} \rfloor)} \mu(d)d^2sum(\lfloor \frac{n}{gd} \rfloor,\lfloor \frac{m}{gd} \rfloor)$

$\quad\quad=\sum_{D=1}^{min(n,m)}sum(\lfloor \frac{n}{D} \rfloor,\lfloor \frac{m}{D} \rfloor) \sum_{d|D} \frac{D}{d}\mu(d)d^2$

$\quad\quad=\sum_{D=1}^{min(n,m)}sum(\lfloor \frac{n}{D} \rfloor,\lfloor \frac{m}{D} \rfloor) \sum_{d|D} dD\times\mu(d)$

$ANS=\sum_{D=1}^{min(n,m)}sum(\lfloor \frac{n}{D} \rfloor,\lfloor \frac{m}{D} \rfloor) w[D]$

1.对于一个质数p，$w[p]=1\times p\times 1+p\times p \times(-1)$

2.对于枚举到的i和质数p，

如果i%p!=0，则运用积性函数的性质：$w[i\times p]=w[i]\times w[p]$

否则，不难发现，新增的p导致产生的其他加项中$\mu(d)=0$，所以直接$w[i\times p]=w[i]\times p$

(w[ ]的推导仔细想想哈，其实并不麻烦的)

#include<cstdio>
#include<cstring>
#include<iostream>
#define MAXN 10000050
using namespace std;
const int mod=100000009;
int w[MAXN],pw[MAXN];
void Sieve(){
static bool np[MAXN];
static int prime[MAXN],pnt;
w[1]=1,pw[1]=1;
for(int i=2;i<=10000000;i++){
if(!np[i]) prime[++pnt]=i,w[i]=((1ll*i-1ll*i*i%mod)%mod+mod)%mod;
for(int j=1;j<=pnt&&i<=10000000/prime[j];j++){
np[i*prime[j]]=1;
if(i%prime[j]) w[i*prime[j]]=((-1ll*w[i]*prime[j]%mod*prime[j]%mod+mod)%mod+1ll*w[i]*prime[j]%mod)%mod;
else{w[i*prime[j]]=1ll*w[i]*prime[j]%mod; break;}
}
pw[i]=(1ll*pw[i-1]+w[i])%mod;
}
}
int sum(int n,int m){
return ((1ll*(1+n)*n/2%mod)*(1ll*(1+m)*m/2%mod))%mod;
}
int main(){
Sieve(); int Case,n,m,ans,mini;
scanf("%d",&Case);
for(int i=1;i<=Case;i++){
scanf("%d%d",&n,&m);
ans=0; mini=min(n,m);
for(int d=1,last;d<=mini;d=last+1){
last=min(n/(n/d),m/(m/d));
ans=(1ll*ans+1ll*(pw[last]-pw[d-1]+mod)%mod*sum(n/d,m/d)%mod)%mod;
}
printf("%d\n",(ans+mod)%mod);
}
return 0;
}


Do not go gentle into that good night.
Rage, rage against the dying of the light.
————Dylan Thomas
posted @ 2018-01-12 10:41  *ZJ  阅读(104)  评论(0编辑  收藏  举报