Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- int n, x, y, res = 0;
- cin >> n >> x >> y;
- res += min(x, y);
- n--;
- int lcm = x * y / __gcd(x, y);
- int step = lcm / x + lcm / y;
- res += n / step * lcm;
- n %= step;
- int add = int(1e9);
- for (int i = 0; i <= n; i++)
- add = min(add, max(i * x, (n - i) * y) );
- res += add;
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement