정수론(Number theory)

백준 13241번: 최소공배수

cepiloth 2018. 7. 3. 09:49
반응형

https://www.acmicpc.net/problem/13241


1. 문제

두 수의 최소 공배수를 찾는 문제


2. 알고리즘

키워드 - 유클리드 호제법, GCD


3. 코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>         // greater 사용 위해 필요  
#include <string>
#include <map>
#include <math.h>
using namespace std;
long long int gcd(long long int a,long long  int b) {
    return (a % b == ? b : gcd(b,a%b));
}
int main() {
 
    long long int a, b;
    cin >> a >> b;
 
    long long int sol =  gcd(a,b);
    cout << a * b / sol;
    return 0;
}
cs


반응형