Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define ll long long
- #define int ll
- using namespace std;
- signed main()
- {
- int x, y;
- cin >> x >> y;
- int ans = -1;
- if (y >= 2 * x - 1) {
- ans = x;
- }
- else {
- int m = y % x;
- int n = x - 1;
- ans = 0;
- for (int i = m; i >= 1; i--) {
- if (n <= 0) break;
- int k = n / i;
- n -= k * i;
- ans += (x + i) * k;
- }
- ans = ans - ans % x;
- if (m == 0) {
- ans = -1;
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement