【bzoj 2301】Problem b(莫比乌斯反演)
来源:互联网 发布:关联数组和索引数组 编辑:程序博客网 时间:2024/06/04 19:15
传送门biu~
#include<bits/stdc++.h>using namespace std;int u[100005],prime[100005],tp;bool b[100005];void get_u(){ u[1]=1; for(int i=2;i<=100000;++i){ if(!b[i]) prime[++tp]=i,u[i]=-1; for(int j=1;j<=tp && i*prime[j]<=100000;++j){ b[i*prime[j]]=true; if(i%prime[j]==0) break; u[i*prime[j]]=-u[i]; } } for(int i=1;i<=100000;++i) u[i]+=u[i-1];}long long calc(int n,int m,int k){ n/=k; m/=k; int pre; long long re=0; for(int i=1;i<=n && i<=m;i=pre+1){ pre=min(n/(n/i),m/(m/i)); re+=1ll*(n/i)*(m/i)*(u[pre]-u[i-1]); } return re;}int main(){ int n; scanf("%d",&n); get_u(); while(n--){ int a,b,c,d,k; scanf("%d%d%d%d%d",&a,&b,&c,&d,&k); printf("%lld\n",calc(b,d,k)+calc(a-1,c-1,k)-calc(a-1,d,k)-calc(b,c-1,k)); } return 0;}
阅读全文
0 0
- BZOJ 2301 Problem b (莫比乌斯反演)
- BZOJ 2301 Problem b(莫比乌斯反演)
- BZOJ 2301-Problem b(莫比乌斯反演)
- 【bzoj 2301】Problem b(莫比乌斯反演)
- [BZOJ 2301][HAOI2011] Problem b 莫比乌斯反演
- bzoj 2301: [HAOI2011]Problem b 【莫比乌斯反演】
- BZOJ 2301: [HAOI2011]Problem b - 莫比乌斯反演
- [莫比乌斯反演] BZOJ 2301 [HAOI2011]Problem b
- 【BZOJ 2301】Problem B 莫比乌斯反演
- BZOJ 2301: [HAOI2011]Problem b【莫比乌斯反演
- bzoj 2301: [HAOI2011]Problem b 莫比乌斯反演
- BZOJ 2301 Problem b (莫比乌斯反演)
- bzoj 2301: [HAOI2011]Problem b(莫比乌斯反演)
- BZOJ 2301: [HAOI2011]Problem b (莫比乌斯反演)
- BZOJ 2301 Problem b(莫比乌斯反演+容斥)
- BZOJ 2301: [HAOI2011]Problem b(莫比乌斯反演 + 容斥原理 + 分块优化)
- BZOJ 2301: [HAOI2011]Problem b(莫比乌斯反演,分块,容斥)
- BZOJ 2301 [HAOI2011]Problem b (莫比乌斯反演)
- Ubuntu vi设置行号
- User-Agent 汇总
- 膨胀软件工程师小王:第5工作日——Luna
- jQuery Easyui框架整理
- Lucene使用笔记
- 【bzoj 2301】Problem b(莫比乌斯反演)
- ActiveMQ消息中间件之队列模式和主题模式详解
- 4-Thread类详解以及线程状态分析
- 12.2每周三道题+2道测试题
- Jwt创建身份令牌Token
- tomcat启动问题:十二月 08, 2017 11:28:01 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息:
- 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)
- java 数论板子
- poj2892 Tunnel Warfare