https://www.acmicpc.net/problem/4948
import sys
import math
input = sys.stdin.readline
while True:
N = int(input())
if N == 0:
break
maxN = 2*N
is_prime = [True for x in range(maxN+1)]
p = 2
# 에라토스테네스의 체 알고리즘 이용
while p*p <= maxN:
if is_prime[p]:
for i in range(p*p, maxN+1, p):
is_prime[i] = False
p += 1
dap = [p for p in range(N+1, maxN+1) if is_prime[p]]
print(len(dap))'코딩테스트 > 코딩테스트 문제풀이' 카테고리의 다른 글
| [Python] 백준 <1966-프린터 큐> (0) | 2025.06.11 |
|---|---|
| [Python] 백준 <1058-친구> (0) | 2025.06.09 |
| [Python] 백준 <14888-연산자 끼워넣기> (0) | 2025.06.06 |
| [Python] 백준 <15652-N과 M (4)> (0) | 2025.06.04 |
| [Python] 백준 <14889-스타트와 링크> (0) | 2025.05.28 |