알고리즘 문제/수학(math)
(백준 알고리즘 문제풀이) 5618번 공약수
재코딩
2022. 7. 27. 21:41
반응형
문제
문제 접근
- 최대 공약수를 구한다.
- 최대 공약수의 약수들을 오름차순으로 나열
- import math를 이용하면 쉽게 해결 가능
- math.gcd (최대 공약수)
코드
import sys
import math
input = sys.stdin.readline
n = int(input())
n_list = list(map(int, input().split()))
# greatest common factor
gcf = math.gcd(*n_list)
for i in range(1, gcf+1):
if gcf % i == 0:
print(i)
반응형