// 최대공약수
auto gcd(long long A, long long B){
if (B == 0)
return A;
else
return gcd(B, A%B);
}
// 최소공배수
auto lcm (long long A, long long B){
return A*B/gcd(A,B);
}
§my solution
#include <iostream>
#include <algorithm>
using namespace std;
// 최대공약수
auto gcd(long long A, long long B){
if (B == 0)
return A;
else
return gcd(B, A%B);
}
// 최소공배수
auto lcm (long long A, long long B){
return A*B/gcd(A,B);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
long long A, B; cin >> A >> B;
cout << lcm(A,B);
}
백만자리라는 문제를 안읽고 풀어서 틀렸다. lon long을 써줘야 함.
§my solution
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
auto gcd(long long a, long long b){
if (b == 0)
return a;
else
return gcd(b, a%b);
}
auto lcm(long long a, long long b){
return a*b / gcd(a, b);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int num; cin >> num;
vector<long long> v1;
vector<long long> v2;
for (int i = 0; i < num; i++) {
int a, b; cin >> a >> b;
v1.push_back((a));
v2.push_back((b));
}
for (int i = 0; i < num; i++) {
cout << lcm(v1.at(i), v2.at(i)) << '\n';
}
}