fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define all(v) v.begin(), v.end()
  5.  
  6. int fun(int t, int x, int y)
  7. {
  8. int cnt = 0;
  9. cnt = (t / x) + (t / y);
  10. return cnt;
  11. }
  12.  
  13. signed main()
  14. {
  15.  
  16. int n, i, x, y, ans = 0, cnt = 0, m;
  17.  
  18. cin >> n >> x >> y;
  19.  
  20. ans = min(x, y);
  21. n--;
  22.  
  23. int l = 0;
  24. int r = 1e18;
  25.  
  26. while (l <= r)
  27. {
  28.  
  29. int m = l + (r - l) / 2;
  30. cnt = fun(m, x, y);
  31.  
  32. if (cnt < n)
  33. l = m + 1;
  34. else
  35. r = m - 1;
  36. }
  37.  
  38. cout << ans + l << endl;
  39. }
Success #stdin #stdout 0s 5552KB
stdin
4 1 1
stdout
3