hdu 1695 GCD(容斥)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} /********************************************************************/ const int maxn = 1e5+;
vector<int> pri[maxn]; //分解成的质数
void init(){
for(int i = ;i < maxn; i++){
int now = i;
for(int j = ;j*j <= now;j++){
if(now%j == ){
pri[i].push_back(j);
while(now%j == ) now /= j;
}
if(now == ) break;
}
if(now > )
pri[i].push_back(now);
}
} int solve(int x, int pos){
int res = ;
for(int i = ;i < ( << pri[x].size());i++){
int num = ;
int tmp = ;
for(int j = ;j < pri[x].size();j++){
if((i >> j)& ){
num++;
tmp *= pri[x][j];
}
}
if(num & ) res += pos/tmp;
else res -= pos/tmp;
}
return pos - res;
} int main(){
init();
int t;
t = read();
for(int i = ;i <= t;i++){
int a, b, c, d, k;
//a = 1, d = 1;
a = read(); b = read(); c = read(); d = read(); k = read();
if(k == ){
printf("Case %d: 0\n", i);
continue;
}
b /= k, d /= k;
if(b < d) swap(b, d);
ll ans = ;
for(int j = ;j <= b;j++){
ans += solve(j, min(j, d));
}
printf("Case %d: %lld\n", i, ans);
}
return ;
}
hdu 1695 GCD(容斥)的更多相关文章
- HDU 1695 GCD 容斥
GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...
- hdu 1695 GCD 容斥+欧拉函数
题目链接 求 $ x\in[1, a] , y \in [1, b] $ 内 \(gcd(x, y) = k\)的(x, y)的对数. 问题等价于$ x\in[1, a/k] , y \in [1, ...
- HDU - 1695 GCD (容斥+枚举)
题意:求区间1<=i<=b与区间1<=j<=d之间满足gcd(i,j) = k 的数对 (i,j) 个数.(i,j)与(j,i) 算一个. 分析:gcd(i,j)=k可以转化为 ...
- hdu 5514 Frogs(容斥)
Frogs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 5213 分块 容斥
给出n个数,给出m个询问,询问 区间[l,r] [u,v],在两个区间内分别取一个数,两个的和为k的对数数量. $k<=2*N$,$n <= 30000$ 发现可以容斥简化一个询问.一个询 ...
- HDU 2588 思维 容斥
求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$. 首先,假定$(x, n)=m$ ...
- hdu 1695 GCD 欧拉函数 + 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1695 要求[L1, R1]和[L2, R2]中GCD是K的个数.那么只需要求[L1, R1 / K] 和 [L ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 1695 GCD(容斥定理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- 数论 + 容斥 - HDU 1695 GCD
problem's Link mean 给定五个数a,b,c,d,k,从1~a中选一个数x,1~b中选一个数y,使得gcd(x,y)=k. 求满足条件的pair(x,y)数. analyse 由于b, ...
随机推荐
- C++笔记之外部类访问内部类的私有成员
如下图所示 内部类可以访问外部类的私有成员 而外部类无法访问内部类的私有成员 为了能让外部类访问内部类的私有成员,将外部类声明为内部类的友元类即可 #include <iostream> ...
- RequestDispatcher用法
1.具体用法: RequestDispatcher dispatcher = req.getRequestDispatcher("updateByUserId_001.jsp"); ...
- Java其实不支持垃圾回收
Java其实不支持垃圾回收.如果真的支持的话,大多数Java程序在运行的一开始就应该把程序本身删除,因为这些程序本身就是垃圾. // TODO: This is a 分割线. Please no ...
- 有关SharedPreference的使用
1.不要使你的文件过大 Sp 在创建的时候会吧整个xml问文件全部载入内存,如果你的文件比较大: 1.第一次从sp取值时,会阻塞主线程,使页面卡顿. 2.解析sp的时候会产生大量的临时对象,导致频繁G ...
- progressbar请求数据 加载demo1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...
- ThinkPHP使用方法与心得
ThinkPHP相信PHP程序员对它并不陌生,通过自己的学习在此发表个人看法,也为以后自己查找ThinkPHP方面的知识更加方便. 一.mvc及数据库CURD操作流程: 1.新建数据库:数据库名称:1 ...
- HDU5877 Weak Pair dfs + 线段树/树状数组 + 离散化
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5877 题意: weak pair的要求: 1.u是v的祖先(注意不一定是父亲) 2.val[u]*va ...
- Discuz/X3.1去掉标题中的Powered by Discuz!以及解决首页标题后的"-"
虽然不提倡大家去掉版权信息,但是在实际操作的时候还是去掉,毕竟每个页面标题最后面出现”Powered by Discuz!“会显得页面标题比较冗长. 经过本人的实践,论坛里也有操作方法,不过那个操作方 ...
- margin-top 为什么会影响父元素的 margin-top
1.原因: In this specification, the expression collapsing margins means that adjoining margins (no non ...
- ACM2016级新生第三周训练赛
本次是弱校题解-比赛链接 备用链接 题目还是比较基础,比较简单.认真补题,学会学习. A -人见人爱A^B 题解: 求 A的B次方,我们可以用循环进行累乘操作,进而计算出次方.因为题目要求只需要求出最 ...