Reputation: 180
This is my source code, which I try to pass to the least common multiplier task:
#include <iostream>
#include "algorithm"
using namespace std;
using ll = long long;
using ld = long double;
long long gcd(int a, int b) {
while (b > 0) {
a %= b;
swap(a, b);
}
return a;
}
long long lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int x, y;
cin >> x >> y;
cout << lcm(x, y);
}
What's wrong with it? I tried many times. Please, help me!
Upvotes: 0
Views: 99
Reputation: 334
what about negative numbers? Try calculating the GCD(abs(x), abs(y)), it's the same as GCD(x, y)
Upvotes: 1