首页 > 代码库 > 数学/Codeforces 483b Friends and Presents

数学/Codeforces 483b Friends and Presents

 1 #include<cstdio> 2 using namespace std; 3 long long m,cnt1,cnt2,x,y; 4 long long gcd(long long a,long long b) 5 { 6     if (b==0) return a; 7     return gcd(b,a % b); 8 } 9 long long lcm(long long a,long long b)10 {11     return a*b/gcd(a,b);12 }13 bool f(long long n)14 {15     long long xx=n-n/x,yy=n-n/y;16     if (xx<cnt1 || yy<cnt2) return false;17     long long both=n/m;18     if ((n-both)<cnt1+cnt2) return false;19     return true;20 }21 int main()22 {23     scanf("%lld%lld%lld%lld",&cnt1,&cnt2,&x,&y);24     m=lcm(x,y);25     long long l=1,r=1e10;26     while (l<r)27     {28         long long mid=(l+r)/2;29         if (f(mid)) r=mid;30         else l=mid+1;31     }32     printf("%lld\n",r);33     return 0;34 }

 

数学/Codeforces 483b Friends and Presents