BOJ - 5618 - 공약수

Updated:

import sys

def GCD(a, b):
    if a == 0:
        return b
    return GCD(b % a, a)

def solution():
    N = int(sys.stdin.readline())
    arr = list(map(int, sys.stdin.readline().split()))

    temp = GCD(arr[0], GCD(arr[1], arr[-1]))
    for i in range(1, (temp // 2) + 1):
        if temp % i == 0:
            print(i)
    print(temp)

solution()

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

Categories:

Updated:

Leave a comment