백준/약수, 배수와 소수

백준 - 2581 (python)

SooHw 2024. 2. 27. 16:01

 

 

조건문으로 계속 검사하면 시간이 오래걸릴것 같아서 배열에 저장해서 합, 최소값을 구했다

 

def find(num):
    for i in range(2, num):
        if num % i == 0:
            return 0
    if num == 1:
        return 0


M = int(input())
N = int(input())
arr = []
for i in range(M, N + 1):
    if find(i) != 0:
        arr.append(i)
if len(arr) == 0:
    print("-1")
else:
    print(sum(arr))
    print(min(arr))

'백준 > 약수, 배수와 소수' 카테고리의 다른 글

백준 - 11653 (python)  (0) 2024.02.29
백준 - 1978 (python)  (0) 2024.02.26
백준 - 9506 (python)  (0) 2024.02.22
백준 - 2501 (python)  (0) 2024.02.22
백준 - 5086 (python)  (0) 2024.02.21