bzoj2301
来源:互联网 发布:停车源码 编辑:程序博客网 时间:2024/06/05 09:08
莫比乌斯反演+分块优化
PoPoQQQ的课件讲得很详细,大赞~!
#include<map>#include<stack>#include<queue>#include<ctime>#include<cmath>#include<string>#include<cstdio>#include<cstdlib>#include<cstring>#include<utility>#include<iostream>#include<algorithm>const int SIZE = 50005;int mu[SIZE], prime[SIZE>>3], tot;bool check[SIZE]; int sum[SIZE];void PreWork(){ sum[1] = mu[1] = 1; for(int i = 2; i < SIZE; i++) { if(!check[i]) prime[++tot] = i, mu[i] = -1; sum[i] = sum[i-1] + mu[i]; for(int j = 1, t; j <= tot && (t = prime[j]*i) < SIZE; j++) { check[t] = true; if(i%prime[j]) mu[t] = -mu[i]; else {mu[t] = 0; break;} } } }long long Count(int p,int q){// gcd(i,j)=1 [1,p] [1,q] long long ret = 0; if(p > q) std::swap(p,q); for(int i = 1, next = 0; i <= p; i = next+1) { next = std::min(p/(p/i), q/(q/i)); ret += (long long)(sum[next]-sum[i-1])*(p/i)*(q/i); } return ret;}int main(){ int n;#ifndef ONLINE_JUDGE freopen("bzoj2301.in","r",stdin); freopen("bzoj2301.out","w",stdout);#endif scanf("%d",&n); PreWork(); while(n--) { int a, b, c, d, k;long long ans; scanf("%d%d%d%d%d",&a,&b,&c,&d,&k); ans = Count(b/k,d/k) - Count(b/k,(c-1)/k) - Count((a-1)/k,d/k) + Count((a-1)/k,(c-1)/k); printf("%lld\n",ans); }#ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0;}
0 0
- bzoj2301
- bzoj2301
- bzoj2301
- bzoj2301
- BZOJ2301 Problemb
- 【HAOI2011】【BZOJ2301】ProblemB
- BZOJ2301【HAOI2011】Problem b
- bzoj2301: [HAOI2011]Problem b
- [BZOJ2301][HAOI2011]Problem b
- bzoj2301【HAOI2011】Problem b
- Problem b [HAOI2011][bzoj2301]
- 【bzoj2301】 [HAOI2011]Problem b
- bzoj2301 [HAOI2011]Problem b
- 【bzoj2301】[HAOI2011]Problem b
- BZOJ2301: [HAOI2011]Problem b
- bzoj2301 [HAOI2011]Problem b
- BZOJ2301 Problem b
- HYSBZ/BZOJ2301 problem b
- 【末世旅行之C语言】C语言经典试题小集合
- Filter
- Linux: centos软件包管理的3种方式
- 算法学习:最富盛名的程序设计竞赛
- javascript笔记(一)
- bzoj2301
- Flash和Arduino进行交互时不断重连
- Python删除列表重复数据以及效率问题
- bzoj2440
- HDU 4858 Shaolin(map暴力)
- 并行笔记
- Unity 3D中的内存管理
- 如何使用回调函数
- lua语言连接redis