[莫比乌斯反演] BZOJ1101: [POI2007]Zap
2017-09-27 21:22
267 查看
随手点到这个漏掉的裸题,水一发…
#include<cstdio> #include<algorithm> using namespace std; const int maxn=50005; typedef long long LL; int n,N=50000,p[maxn],mu[maxn]; bool vis[maxn]; void get_mu(){ mu[1]=1; for(int i=2;i<=N;i++){ if(!vis[i]) p[++p[0]]=i, mu[i]=-1; for(int j=1;j<=p[0]&&(LL)i*p[j]<=N;j++){ vis[i*p[j]]=true; if(i%p[j]==0){ mu[i*p[j]]=0; break; } mu[i*p[j]]=-mu[i]; } } for(int i=1;i<=N;i++) mu[i]+=mu[i-1]; } int _test; LL ans; int main(){ freopen("bzoj1101.in","r",stdin); freopen("bzoj1101.out","w",stdout); get_mu(); scanf("%d",&_test); while(_test--){ int n,m,d; scanf("%d%d%d",&n,&m,&d); ans=0; n/=d; m/=d; int _min=min(n,m); for(int i=1,nxt;i<=_min;i=nxt+1){ nxt=min(n/(n/i),m/(m/i)); ans+=(LL)(n/i)*(m/i)*(mu[nxt]-mu[i-1]); } printf("%lld\n",ans); } return 0; }
相关文章推荐
- 【莫比乌斯反演】BZOJ1101 [POI2007]zap
- 【bzoj1101】[POI2007]Zap 莫比乌斯反演
- [BZOJ 1101][POI2007]Zap:莫比乌斯反演
- BZOJ1101 [POI2007]Zap 【莫比乌斯反演】
- BZOJ 1101 [POI2007]Zap 莫比乌斯反演
- BZOJ1101 [POI2007]Zap 【莫比乌斯反演】
- BZOJ 1101 [POI2007]Zap | 莫比乌斯反演
- bzoj1101: [POI2007]Zap 莫比乌斯反演
- 【莫比乌斯反演+分块】BZOJ1101-[POI2007]Zap
- bzoj1101[POI2007]Zap-莫比乌斯反演
- 【莫比乌斯反演】BZOJ1101 [POI2007]Zap
- bzoj 1101 [POI2007]Zap 莫比乌斯反演
- bzoj1101 [POI2007]Zap 莫比乌斯反演
- BZOJ 1101: [POI2007]Zap 莫比乌斯反演
- [莫比乌斯反演] BZOJ 1101 [POI2007]Zap
- BZOJ 1101: [POI2007]Zap [莫比乌斯反演]
- bzoj 1101 [POI2007]Zap - 莫比乌斯反演
- BZOJ 1101: [POI2007]Zap 莫比乌斯反演
- 【BZOJ】1101: [POI2007]Zap(莫比乌斯+分块)
- 【BZOJ】【P1101】【POI2007】【Zap】【题解】【莫比乌斯反演】