Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // uzumaki naruto
- #include <bits/stdc++.h>
- #define each(v,c) for(typeof((c).begin()) v = (c).begin(); v != (c).end(); ++v)
- #define pb push_back
- #define mp make_pair
- #define sz(a) ((int)(a.size()))
- #define all(a) (a).begin(), (a).end()
- #define fi first
- #define se second
- #define TRACE
- using namespace std;
- #ifdef TRACE
- #define debug(a,n) cerr << "["; for(int i = 0; i < n; ++i) cerr << a[i] << " ";cerr << "\b]\n";
- #define dbg(args...) {debug1,args; cerr<<endl;}
- #define pause() cin.get();cin.get();
- #else
- #define debug(a,n)
- #define dbg(args...)
- #define pause()
- #endif
- struct debugger {
- template<typename T> debugger& operator , (const T& v) {
- cerr<<v<<" "; return *this;
- }
- } debug1;
- template <typename T1, typename T2>
- inline ostream& operator << (ostream& os, const pair<T1, T2>& p) {
- return os << "(" << p.first << ", " << p.second << ")";
- }
- template<typename T>
- inline ostream &operator << (ostream & os,const vector<T>& v) {
- bool first = true; os << "[";
- for (typename vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
- if(!first) os << ", ";
- os << *ii; first = false;
- }
- return os << "]";
- }
- typedef long long LL;
- typedef pair<int,int> pii;
- typedef vector<int> vi;
- LL x,y,z;
- LL cnt1,cnt2;
- LL f(LL a,LL b){
- LL n = a/b;
- LL ans = a - n;
- return ans;
- }
- bool valid(LL mid){
- LL v1 = f(mid,x);
- LL v2 = f(mid,y);
- LL v3 = mid - (mid/x + mid/y - mid/z);
- if (v1 >= cnt1 and v2 >= cnt2){
- if (v1+v2-v3 >= cnt1+cnt2)
- return true;
- }
- return false;
- }
- void solve(){
- cin >> cnt1 >> cnt2 >> x >> y;
- z = y*x;
- LL st = 1LL , en = 1000000000000000000LL;
- while(st < en){
- LL mid = (st+en)/2LL;
- if (valid(mid)) en = mid;
- else st = mid+1;
- }
- cout << en << "\n";
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- solve();
- return 0;
- }
- [close]
Advertisement
Add Comment
Please, Sign In to add comment