728x90
반응형
이 문제 또한 저번에 봤던 에라토스테네스의 체를 사용해 쉽게 풀 수 있다.
while True:
n = int(input())
if n == 0:
break
n1, n2= n+1, 2*n
li = [1]*(n2+1)
for i in range(2, int((n2+1)**0.5) + 1):
if li[i] == 1:
for j in range(i+i, n2+1, i):
li[j] = 0
cnt = 0
for i in range(n1, n2+1):
if li[i] == 1 and i > 1:
cnt += 1
print(cnt)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 5218번 알파벳 거리(python) (0) | 2020.02.12 |
---|---|
백준 알고리즘 5086번 배수와 약수(python) (0) | 2020.02.12 |
백준 알고리즘 4673번 셀프 넘버(python) (0) | 2020.02.12 |
백준 알고리즘 4504번 배수 찾기(python) (0) | 2020.02.12 |
백준 알고리즘 4470번 줄번호(python) (0) | 2020.02.12 |