Advertisement
Malinovsky239

A

Jan 13th, 2012
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n, x, y, res = 0;
  9.     cin >> n >> x >> y;
  10.  
  11.     res += min(x, y);
  12.     n--;
  13.     int lcm = x * y / __gcd(x, y);
  14.  
  15.     int step = lcm / x + lcm / y;
  16.     res += n / step * lcm;
  17.  
  18.     n %= step;
  19.  
  20.     int add = int(1e9);
  21.    
  22.     for (int i = 0; i <= n; i++)
  23.         add = min(add, max(i * x, (n - i) * y) );  
  24.  
  25.     res += add;
  26.  
  27.     cout << res << endl;
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement