//15 ms 0 KB
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
ll n,m,x,y;
bool check(ll mid)
{
ll num1=mid/x;
ll num2=mid/y;
ll both=mid/(x*y);
ll count=mid-num1-num2+both;
ll cnt1=num1-both;
ll cnt2=num2-both;
ll res1=max(m-cnt1,(ll)(0));
ll res2=max(n-cnt2,(ll)(0));
return (res1+res2<=count);
}
int main()
{
while(scanf("%lld%lld%lld%lld",&n,&m,&x,&y)!=EOF)
{
ll l=1,r=1e10,mid;
while(l<r)
{
mid=(l+r)>>1;
if(check(mid))r=mid;
else l=mid+1;
}
printf("%lld\n",r);
}
return 0;
}
codeforces 483B. Friends and Presents
最新推荐文章于 2020-07-29 19:53:48 发布