chang2394

Untitled

Oct 24th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. // uzumaki naruto
  2. #include <bits/stdc++.h>
  3. #define each(v,c)  for(typeof((c).begin()) v = (c).begin(); v != (c).end(); ++v)
  4. #define pb         push_back
  5. #define mp         make_pair
  6. #define sz(a)      ((int)(a.size()))
  7. #define all(a)     (a).begin(), (a).end()
  8. #define fi         first
  9. #define se         second
  10. #define TRACE
  11. using namespace std;
  12.  
  13. #ifdef TRACE
  14. #define debug(a,n)    cerr << "["; for(int i = 0; i < n; ++i) cerr << a[i] << " ";cerr << "\b]\n";
  15. #define dbg(args...)  {debug1,args; cerr<<endl;}
  16. #define pause()       cin.get();cin.get();
  17.  
  18. #else
  19.  
  20. #define debug(a,n)
  21. #define dbg(args...)
  22. #define pause()
  23.  
  24. #endif
  25.  
  26. struct debugger {
  27.     template<typename T> debugger& operator , (const T& v) {
  28.         cerr<<v<<" "; return *this;
  29.     }
  30. } debug1;
  31.  
  32. template <typename T1, typename T2>
  33. inline ostream& operator << (ostream& os, const pair<T1, T2>& p) {
  34.     return os << "(" << p.first << ", " << p.second << ")";
  35. }
  36.  
  37. template<typename T>
  38. inline ostream &operator << (ostream & os,const vector<T>& v) {
  39.     bool first = true; os << "[";
  40.     for (typename vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
  41.         if(!first) os << ", ";
  42.         os << *ii; first = false;
  43.     }
  44.     return os << "]";
  45. }
  46.  
  47. typedef long long LL;
  48. typedef pair<int,int> pii;
  49. typedef vector<int> vi;
  50.  
  51. LL x,y,z;
  52. LL cnt1,cnt2;
  53.  
  54. LL f(LL a,LL b){
  55.     LL n = a/b;
  56.     LL ans = a - n;
  57.     return ans;
  58. }
  59.  
  60. bool valid(LL mid){
  61.     LL v1 = f(mid,x);
  62.     LL v2 = f(mid,y);
  63.     LL v3 = mid - (mid/x + mid/y - mid/z);
  64.  
  65.     if (v1 >= cnt1 and v2 >= cnt2){
  66.         if (v1+v2-v3 >= cnt1+cnt2)
  67.             return true;
  68.     }
  69.     return false;
  70. }
  71.  
  72. void solve(){
  73.     cin >> cnt1 >> cnt2 >> x >> y;
  74.     z = y*x;
  75.  
  76.     LL st = 1LL , en = 1000000000000000000LL;
  77.     while(st < en){
  78.         LL mid = (st+en)/2LL;
  79.         if (valid(mid)) en = mid;
  80.         else st = mid+1;
  81.     }
  82.     cout << en << "\n";
  83. }
  84.  
  85. int main()
  86. {
  87.     ios_base::sync_with_stdio(0);
  88.     solve();
  89.     return 0;
  90. }
  91.  
  92. [close]
Advertisement
Add Comment
Please, Sign In to add comment