Advertisement
double_trouble

lcm-gcd

Mar 27th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <string>
  5. #include <cstring>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <set>
  9.  
  10. using namespace std;
  11.  
  12.  
  13. long long gcd(int a, int b)
  14. {
  15.     if (b == 0)
  16.         return a;
  17.     return gcd(b, a % b);
  18. }
  19.  
  20. int main()
  21. {
  22.     int x, y;
  23.     cin >> x >> y;
  24.     if (x == y)
  25.     {
  26.         cout << 0 << endl;
  27.         return 0;
  28.     }
  29.  
  30.     if (x > y)
  31.         swap(x, y);
  32.     long long g = gcd(x, y);
  33.     long long l = x / g;
  34.     l *= y;
  35.  
  36.     cout << l - g << endl;
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement