Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. long long int cn1, cn2, x, y;
  8. cin >> cn1 >> cn2 >> x >> y;
  9. long long a = (x*y*(cn1+cn2-1))/(x*y-1);
  10. long long ans = a+1;
  11. if (ans/y - ans/(x*y) > cn1)
  12. {
  13. ans = ((cn2-1)*y)/(y-1)+1;
  14. }
  15. else if (ans/x - ans/(x*y) > cn2)
  16. {
  17. ans = ((cn1-1)*x)/(x-1)+1;
  18. }
  19. cout << ans;
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement