【莫比乌斯反演】[BZOJ2301]Problem b
来源:互联网 发布:千牛 卖家 for mac 编辑:程序博客网 时间:2024/06/06 15:35
思路,这个令
以下是我的代码
#include <bits/stdc++.h>using namespace std;const int MAXN = 50000;int mu[MAXN+10], prime[MAXN+10], pcnt;bool notprime[MAXN+10];long long solve(int n, int m){ long long ret = 0; if(n > m) swap(n, m); for(int i=1, nex;i<=n;i=nex+1){ nex = min(n/(n/i), m/(m/i)); ret += 1LL * (mu[nex] - mu[i-1]) * (n/i) * (m/i); } return ret;}void Init(int t){ mu[1] = 1; int tmp; for(int i=2;i<=t;i++){ if(!notprime[i]){ prime[++pcnt] = i; mu[i] = -1; } for(int j=1;j<=pcnt&&(tmp=prime[j]*i)<=t;j++){ notprime[tmp] = true; if(i % prime[j] == 0){ mu[tmp] = 0; break; } mu[tmp] = -mu[i]; } } for(int i=2;i<=t;i++) mu[i] += mu[i-1];}int main(){ int n; Init(50000); scanf("%d", &n); while(n--){ int k, a, b, c, d; scanf("%d %d %d %d %d", &a, &b, &c, &d, &k); printf("%lld\n", solve(b/k, d/k) - solve((a-1)/k, d/k) - solve((c-1)/k, b/k) + solve((a-1)/k, (c-1)/k)); } return 0;}
0 0
- bzoj2301: [HAOI2011]Problem b 莫比乌斯反演
- 【莫比乌斯反演】[BZOJ2301]Problem b
- BZOJ2301 [HAOI2011]Problem b(莫比乌斯反演)
- 【莫比乌斯反演】【bzoj2301】problem b
- BZOJ2301: [HAOI2011]Problem b 莫比乌斯反演
- 【bzoj2301】[HAOI2011]Problem b 莫比乌斯反演
- 【莫比乌斯反演】[HYSBZ/BZOJ2301]Problem b
- Bzoj2301: [HAOI2011]Problem b:莫比乌斯反演
- [BZOJ2301][HAOI2011]Problem b(莫比乌斯反演)
- 【BZOJ2301】problem b,数论之莫比乌斯反演
- Bzoj2301 [HAOI2011]Problem b 莫比乌斯反演
- 【BZOJ2301】【HAOI2011】Problem b 莫比乌斯反演
- [BZOJ2301][HAOI2011]Problem b(莫比乌斯反演)
- [bzoj2301]problem b 莫比乌斯反演
- bzoj2301 [HAOI2011]Problem b(莫比乌斯反演)
- 【BZOJ2301】【HAOI2011】Problem B(莫比乌斯反演)
- [BZOJ2301][HAOI2011]Problem b(莫比乌斯反演)
- 【BZOJ2301】【HAOI2011】Problem b 莫比乌斯反演+分块+前缀和
- android-ioc
- 安卓打包修改配置
- Matlab画曲线
- 应用发布到sae问题总结
- django静态图片配置
- 【莫比乌斯反演】[BZOJ2301]Problem b
- Spring框架之自动装配
- rhel5.8 ISO yum源配置
- python2.7在windows 64bit下的NumPy函数库的安装
- NEUQ 1287: 防御导弹
- 面试题:用最有效的方式算出2*8等于几
- QMetaObject分析
- IntentFilter
- 继承