HDU
来源:互联网 发布:黑莓8700软件 编辑:程序博客网 时间:2024/05/17 22:24
题意:给定区间
思路:利用容斥定理求得先求得区间
AC代码
#include <cstdio>#include <cmath>#include <cctype>#include <bitset>#include <algorithm>#include <cstring>#include <utility>#include <string>#include <iostream>#include <map>#include <set>#include <vector>#include <queue>#include <stack>using namespace std;#pragma comment(linker, "/STACK:1024000000,1024000000") #define eps 1e-10#define inf 0x3f3f3f3f#define PI pair<int, int> typedef long long LL;const int maxn = 1e4 + 5;LL solve(LL r, int n) { vector<int>p; p.clear(); for(int i = 2; i*i <= n; ++i) { if(n % i == 0) { p.push_back(i); while(n % i == 0) n /= i; } } if(n > 1) p.push_back(n); LL sum = 0; for(int msk = 1; msk < (1<<(p.size())); ++msk) { LL mult = 1, bits = 0; for(int i = 0; i < p.size(); ++i) { if(msk & (1 << i)) { bits++; mult *= p[i]; } } LL cur = r / mult; if(bits & 1) sum += cur; else sum -= cur; } return r - sum;}int main() { LL a, b; int n; int T; scanf("%d", &T); int kase = 1; while(T--) { scanf("%lld%lld%d", &a, &b, &n); LL x = solve(b, n), y = solve(a-1, n); //printf("%lld %lld\n", x, y); printf("Case #%d: %lld\n", kase++, x-y); } return 0;}
如有不当之处欢迎指出!
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- HTTPClient4.5.2学习笔记(三): HTTP状态管理(state management)
- instanceof 的使用
- 谈ArcGIS分数标注的问题 分子分母形式
- Serializ
- 云计算工程师必备技能
- HDU
- Url Post请求
- 内存分配方式
- Android打包常见错误之Export aborted because fatal lint errors were found
- Java面试总结------搬运工也有梦想
- nagios+logstash实时监控java日志(二)
- Eclipse 生成android程序apk文件
- MLlib--多层感知机(MLP)算法原理及Spark MLlib调用实例(Scala/Java/Python)
- Android 利用异常获取调用堆栈信息