Algorithm/Baekjoon

[Python] 21919. 소수 최소 공배수

느낌표 공장장 2021. 9. 14. 23:45

 

# 소수인지 판별하는 함수
def is_pn(n):
    for i in range(2, n):
        if i * i > n:   # 이 뒤는 볼 필요도 없어
            break

        if n % i == 0:  # 소수가 아니라면 ? False 반환
            return False
    return True

n = int(input())  # 수열의 길이
numbers = set(map(int, input().split())) # 입력받는 수열

answer = 1
for n in numbers:
    if is_pn(n):
        answer *= n

if answer == 1:   # 소수 없어
    print(-1)
else:
    print(answer)

* 수열 리스트를 입력받을 때, 중복인 수들이 올 수 있기 때문에 set() 쓰면 된다.

'Algorithm > Baekjoon' 카테고리의 다른 글

[Python] 9095. 1, 2, 3 더하기  (0) 2021.09.19
[Python] 2103. 이친수  (0) 2021.09.19
[Python] 11727. 2xn 타일링 2  (0) 2021.09.19
[Python] 9020. 골드바흐의 추측  (0) 2021.09.14
[Python] 15649. N과 M(1)  (0) 2021.09.07