-
최대공약수와 최소공배수 - 2609Algorithm/BOJ 2020. 1. 20. 05:49123456789101112131415161718192021222324252627//2609#include <iostream>using namespace std;int gcd(int x, int y){while (true){if (x == 0)return y;else if (y == 0)return x;else if (x > y)x = x % y;elsey = y % x;}}int main(){int x, y;cin >> x >> y;int a = gcd(x, y);cout << a << "\n" << x*y/a;}
cs https://www.acmicpc.net/problem/2609
2609번: 최대공약수와 최소공배수
첫째 줄에는 입력으로 주어진 두 수의 최대공약수를,둘째 줄에는 입력으로 주어진 두 수의 최소 공배수를 출력한다.
www.acmicpc.net
유클리드 호제법을 코드로 구현했습니다
'Algorithm > BOJ' 카테고리의 다른 글
효율적인 해킹 - 1325 (0) 2020.02.11 최소 스패닝 트리 - 1197 (0) 2020.01.30 Strongly Connected Component - 2150 (0) 2020.01.20 단절선 - 11400 (1) 2020.01.10 단절점 - 11266 (0) 2020.01.10