Algorithm/백준
C++ 알고리즘 - 백준 2609 최대공약수와 최소공배수
마루설아
2024. 12. 28. 17:17
https://www.acmicpc.net/problem/2609
#include <iostream>
#define endl "\n"
using namespace std;
int main(void) {
// C++ Init
ios::sync_with_stdio(false);
cin.tie(NULL);
int input1, input2;
cin >> input1 >> input2;
// 최대공약수
int yak1 = input1;
int yak2 = input2;
while (yak1 != yak2) {
if (yak1 > yak2) yak1 -= yak2;
else yak2 -= yak1;
}
cout << yak1 << endl;
// 최소공배수
int bae1 = input1;
int bae2 = input2;
while (bae1 != bae2) {
if (bae1 > bae2) bae2 += input2;
else bae1 += input1;
}
cout << bae1;
}