# bzoj2005 [NOI2010]能量采集 莫比乌斯反演

$gcd(x,y)=k$$x=ak,y=bk.$

$(x',y')$珂以取的值为：$(a,b),(2a,2b),...,((k-1)a,(k-1)b)$

$ans=\Large\Sigma\large_{i=1}^{N}\Large\Sigma\large_{j=1}^M(2(gcd(i,j)-1)+1)$
$=2\Large\Sigma\large_{i=1}^N\Large\Sigma\large_{i=1}^Mgcd(i,j)-N*M$

### 毒瘤代码

#include<stdio.h>
#include<cstring>
#include<algorithm>
#define re register int
#define rl register ll
using namespace std;
typedef long long ll;
re x=0,f=1;
char ch=getchar();
while(ch<'0' || ch>'9') {
if(ch=='-')	f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9') {
x=10*x+ch-'0';
ch=getchar();
}
return x*f;
}
const int Size=100005;
int tot,prime[Size],mu[Size];
bool vis[Size];
void getp(int maxn) {
mu[1]=1;
for(re i=2; i<=maxn; i++) {
if(!vis[i]) {
prime[++tot]=i;
mu[i]=-1;
}
for(re j=1; j<=tot && i*prime[j]<=maxn; j++) {
vis[i*prime[j]]=true;
if(i%prime[j]==0)	break;
mu[i*prime[j]]=-mu[i];
}
}
}
int main() {
int minn=min(n,m);
getp(minn);
ll ans=0;
for(re t=1; t<=minn; t++) {
int lst;
ll sum=0;
for(re i=t; i<=minn; i+=t) {
sum+=(ll)mu[i/t]*(n/i)*(m/i);
}
ans+=sum*t;
}
printf("%lld",(ans<<1ll)-(ll)n*m);
return 0;
}


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客