VioletaBabel

1145번: 적어도 대부분의 배수 본문

백준/백준-C++
1145번: 적어도 대부분의 배수
Beabletoet 2018. 12. 6. 13:20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<cstdio>
using namespace std;
int LCM(int a, int b)
{
    int t = a * b;
    for (int temp; a%b != 0; b = temp % b)
    {
        temp = a;
        a = b;
    }
    return t / b;
}
int main()
{
    int num[5];
    int best = 1000000;
    for (int i = 5; i--scanf("%d", num + i));
    for (int i = 0; i < 3++i)
    {
        for (int j = i + 1; j < 4++j)
        {
            for (int k = j + 1; k < 5++k)
            {
                int t = LCM(num[i], LCM(num[j], num[k]));
                best = (t < best) ? t : best;
            }
        }
    }
    printf("%d", best);
}
cs


'백준 > 백준-C++' 카테고리의 다른 글

15953번: 상금 헌터  (0) 2018.12.10
1212번: 8진수 2진수  (0) 2018.12.06
1021번: 회전하는 큐  (0) 2018.12.04
1003번: 피보나치 함수  (0) 2018.06.26
2217번: 로프  (0) 2018.03.20
Comments