지나가던 개발자
[Python] 백준 2581번(소수) 문제 풀이 본문
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)으로 써서 왜 이러지 이러고 있었다 ㅋㅋ
'PS > Python' 카테고리의 다른 글
[Python] 백준 23825번(SASA 모형을 만들어보자) 문제 풀이 (0) | 2022.04.18 |
---|---|
[Python] 백준 10953번(A+B - 6) 문제 풀이 (0) | 2022.04.16 |
[Python] 백준 2231번(분해합) 문제 풀이 (0) | 2022.03.27 |
[Python] 백준 1731번(추론) 문제 풀이 (0) | 2022.03.27 |
[Python] 백준 4101번(크냐?) 문제 풀이 (0) | 2022.03.27 |
Comments