지나가던 개발자

[Python] 백준 2581번(소수) 문제 풀이 본문

PS/Python

[Python] 백준 2581번(소수) 문제 풀이

KwonYongHyeon 2022. 4. 16. 12:39

 

def is_prime(n):
    if n == 1:
        return False
    for i in range(2, n):
        if n % i == 0:
            return False
    return True
    
divisor = []
summ = 0
m = int(input())
n = int(input())
for i in range(m, n+1):
    if is_prime(i):
        summ += i
        divisor.append(i)
        
if len(divisor) == 0:
    print(-1)
else:    
    print(summ)
    print(divisor[0])

 

 is_prime 함수는 이전 글에서 가져왔다.

 

 https://developer-next-to-you.tistory.com/136

 

[Python] 백준 1929번(소수 구하기) 문제 풀이

import math def is_prime(n): if n == 1: return False if n % 2 == 0: if n == 2: return True return False if n % 3 == 0: if n == 3: return True return False if n % 5 == 0: if n == 5: return True retu..

developer-next-to-you.tistory.com

 

 13번 줄에서 (m, n+1)인데 (m, n)으로 써서 왜 이러지 이러고 있었다 ㅋㅋ

Comments