Codeforces Round 275 (Div. 2)
B
Friends and Presents
Codeforces
1800
原题
← AC →
翻译中…

You have two friends. You want to present each of them several positive integers. You want to present $*cnt*_{1}$ numbers to the first friend and $*cnt*_{2}$ 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 $*cnt*_{1}$, $*cnt*_{2}$, $*x*$, $*y*$ ($1 ≤ *cnt*_{1}, *cnt*_{2} < 10^{9}$; $*cnt*_{1} + *cnt*_{2} ≤ 10^{9}$; $2 ≤ *x* < *y* ≤ 3·10^{4}$) — the numbers that are described in the statement. It is guaranteed that numbers $*x*$, $*y*$ are prime.

翻译中…

Output

翻译中…

Print a single integer — the answer to the problem.

翻译中…

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$.

翻译中…

样例

Input #1
3 1 2 3
Output #1
5
InputCopy OutputCopy
Input #2
1 3 2 3
Output #2
4
InputCopy OutputCopy
题目信息
题号
483B
时间限制
1 s
内存限制
256 MB
标签
二分
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。