题目:

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.

In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.

Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.

A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.

Input

The only line contains four positive integers cnt1, cnt2, xy (1 ≤ cnt1, cnt2 < 109; cnt1 + cnt2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers xy are prime.

Output

Print a single integer — the answer to the problem.

Examples
input
3 1 2 3
output
5
input
1 3 2 3
output
4
Note

In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.

In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.

题解:

n-n/x-n/y+n/xy这一部分是两边都能用的,而n/y-n/xy是只能给x集合用的,n/x-n/xy是只能给y集合用的,先分配这两个,分配完之后剩下的再用n-n/x-n/y+n/xy里面的去填。满足条件的话就二分更小的,否则,二分更大的。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL; const LL maxn = 2e11; LL cnt1, cnt2, x, y; bool ok(LL n, LL t1, LL t2) {
t1 = t1 - (n / y - n / (x*y)); if (t1<) t1 = ;
t2 = t2 - (n / x - n / (x*y)); if (t2<) t2 = ;
if (n - n / x - n / y + n / (x*y) >= t1 + t2) return true;
return false;
} int main() {
// freopen("data_in.txt","r",stdin);
while (scanf("%lld%lld%lld%lld", &cnt1, &cnt2, &x, &y) == ) {
LL low = , hig = maxn;
//区间(low,hig]
while (low + <hig) {
LL mid = low + (hig - low) / ;
if (ok(mid, cnt1, cnt2)) {
hig = mid;
}
else {
low = mid;
}
}
printf("%lld\n", hig);
}
return ;
}

CodeForces 483B 二分答案的更多相关文章

  1. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

  2. codeforces 359D 二分答案+RMQ

    上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{ ...

  3. Electric Charges CodeForces - 623C (二分答案)

    大意: 平面上n个点每个点坐标为(x,0)或(0,y), 求任意两点距离平方最大值的最小值. 二分答案, 转化为判定最大值是否<=e, 按$x$排序后, 因为固定左端点, $y$绝对值的最大值是 ...

  4. Codeforces 1132D(二分答案+堆)

    题面 传送门 分析 二分答案,考虑如何判定 可以用贪心的方法,每次找最快没电的电脑,在没电前1单位时间给它充电 正确性显然 实现上可以维护一个堆,存储每个电脑电用完的时刻,每次从堆顶取出最小的一个给它 ...

  5. CodeForces 549H | 二分答案

    参考了这个博客哇 #include<cstdio> #include<algorithm> #include<cstring> #define Max(a,b,c, ...

  6. codeforces 466C 计数 codeforces 483B 二分 容斥

    题意:给你n个数,将他们分成连续的三个部分使得每个部分的和相同,求出分法的种数. 思路:用一个数组a[i]记下从第一个点到当前i点的总和.最后一个点是总和为sum的点,只需求出总和为1/3sum的点和 ...

  7. Codeforces 700A As Fast As Possible(二分答案)

    [题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...

  8. Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)

    链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...

  9. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

随机推荐

  1. 记如何用树莓派3开一个无线AP

    开热点 忘掉自己手动配置吧 create_ap git clone git@github.com:oblique/create_ap.git cd create_ap sudo make instal ...

  2. 解决webview上移

    //解决webview上移 $(".webView").blur(function() { setTimeout(function() { var scrollHeight = d ...

  3. LEFT JOIN个别问题

    SELECT a.loginuser, a.schoolid, count(b.id)FROM vhs_school AS aLEFT JOIN vhs_attence AS b ON a.schoo ...

  4. 使用aapt查看apk包名和启动的activity

    执行命令: aapt dump badging F:\知乎.apk

  5. UVA 514 - Rails ( 铁轨)

    from my CSDN: https://blog.csdn.net/su_cicada/article/details/86939523 例题6-2 铁轨(Rails, ACM/ICPC CERC ...

  6. Ambari搭建hadoop错误记录

    1.ResourceManager启动失败 错误如下 2019-03-24 19:57:00,607 - Error while executing command 'start': Tracebac ...

  7. 4.26-python学习笔记(变量及命名、字符串、格式化字符串print,format,%...)

    参考书目:<Learn Python The Hard Way> cars=100 print('there are ',cars,'cars available.') ##练习5 更多变 ...

  8. 柱体内温度分布图 MATLAB

    对于下底面和侧面绝热,上底面温度与半径平方成正比的柱体,绘制柱体内温度分布图. 这里给出两种尝试:1.散点图:2.切片云图 1. 散点图仿真 首先使用解析算法求的场解值的解析表达,其次求解Bessel ...

  9. 20155308 2016-2017-2《Java程序设计》课堂实践项目

    20155308 2016-2017-2<Java程序设计>课堂实践项目 在java.lang包中有String.split()方法,返回是一个数组 我在应用中用到一些,给大家总结一下,仅 ...

  10. 2017-2018-1 20155329《信息安全技术》实验二——Windows口令破解

    2017-2018-1 20155329<信息安全技术>实验二--Windows口令破解 实验原理 口令破解方法 字典破解: 指通过破解者对管理员的了解,猜测其可能使用某些信息作为密码,利 ...