Advertisement
Apauldin

Untitled

Oct 27th, 2021
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #define ll long long
  3. #define int ll
  4. using namespace std;
  5.  
  6. signed main()
  7. {
  8. int x, y;
  9. cin >> x >> y;
  10. int ans = -1;
  11. if (y >= 2 * x - 1) {
  12. ans = x;
  13. }
  14. else {
  15. int m = y % x;
  16. int n = x - 1;
  17. ans = 0;
  18. for (int i = m; i >= 1; i--) {
  19. if (n <= 0) break;
  20. int k = n / i;
  21. n -= k * i;
  22. ans += (x + i) * k;
  23. }
  24. ans = ans - ans % x;
  25. if (m == 0) {
  26. ans = -1;
  27. }
  28. }
  29. cout << ans;
  30. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement