【BZOJ】【P2301】【HAOI2011】【Problem b】【题解】【莫比乌斯反演】
来源:互联网 发布:数字病理 人工智能 编辑:程序博客网 时间:2024/06/05 21:09
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2301
事实证明刷完一个zap就可以水很多题了……
Code:
#include<cstdio>#include<iostream>#include<algorithm>#include<cctype>using namespace std;typedef long long LL;const int maxn=50005;int T,n,m;bool p[maxn];int u[maxn],prime[maxn];int getint(){int res=0;char c=getchar();while(!isdigit(c))c=getchar();while(isdigit(c))res=res*10+c-'0',c=getchar();return res;}void init(){u[1]=1;for(int i=2;i<maxn;i++){if(!p[i]){prime[++prime[0]]=i;u[i]=-1;}for(int j=1;i*prime[j]<maxn&&j<=prime[0];j++){int K=i*prime[j];p[K]=1;if(i%prime[j]==0){u[K]=0;break;}else u[K]=-u[i];}}for(int i=2;i<maxn;i++)u[i]+=u[i-1];}LL calc(int n,int m,int k){n/=k;m/=k;if(n>m)swap(n,m);LL ans=0;for(int i=1,last;i<=n;i=last+1){last=min(n/(n/i),m/(m/i));ans+=(LL)(u[last]-u[i-1])*(n/i)*(m/i);}return ans;}int main(){T=getint();init();while(T--){int a=getint(),b=getint(),c=getint(),d=getint(),k=getint();LL ans=calc(b,d,k)-calc(a-1,d,k)-calc(b,c-1,k)+calc(a-1,c-1,k);printf("%lld\n",ans);}return 0;}
0 0
- 【BZOJ】【P2301】【HAOI2011】【Problem b】【题解】【莫比乌斯反演】
- [BZOJ 2301][HAOI2011] Problem b 莫比乌斯反演
- bzoj 2301: [HAOI2011]Problem b 【莫比乌斯反演】
- BZOJ 2301: [HAOI2011]Problem b - 莫比乌斯反演
- [莫比乌斯反演] BZOJ 2301 [HAOI2011]Problem b
- BZOJ 2301: [HAOI2011]Problem b【莫比乌斯反演
- bzoj 2301: [HAOI2011]Problem b 莫比乌斯反演
- bzoj 2301: [HAOI2011]Problem b(莫比乌斯反演)
- BZOJ 2301: [HAOI2011]Problem b (莫比乌斯反演)
- BZOJ 2301 HAOI2011 Problem b 容斥原理+莫比乌斯反演
- 莫比乌斯反演 bzoj 2301: [HAOI2011]Problem b模板
- 莫比乌斯反演入门 HDOJ 1695:GCD 、BZOJ 2301: [HAOI2011]Problem b
- BZOJ 2301: [HAOI2011]Problem b(莫比乌斯反演 + 容斥原理 + 分块优化)
- BZOJ 2301: [HAOI2011]Problem b(莫比乌斯反演,分块,容斥)
- Bzoj 2301: [HAOI2011]Problem b(莫比乌斯反演+除法分块)
- BZOJ 2301: [HAOI2011]Problem b(容斥原理+莫比乌斯反演)
- BZOJ 2301: [HAOI2011]Problem b 容斥+莫比乌斯反演
- [BZOJ 2301][HAOI2011]Problem b:莫比乌斯反演+容斥
- hibernate中HQL范例大全
- qt 之 qprogressbar
- hdu 4445 Crazy Tank (暴力枚举)
- c# host web服务器
- handler基础知识转载
- 【BZOJ】【P2301】【HAOI2011】【Problem b】【题解】【莫比乌斯反演】
- PHP 中命名空间的作用
- POJ 3130 How I Mathematician Wonder What You Are! 半平面交求多边形内核是否存在
- FFmpeg filter HOWTO
- 用于实现基本的分页操作工具类
- 2014.10.20 周一-事务
- 利用HttpListenerRequest监听HTTP请求并接收cookie的
- hdu 2089 不要62(数位DP)
- Python(2) variable