백준 1929번 소수 구하기

강기호·2023년 2월 8일
0

백준

목록 보기
1/10

작성한 코드

import sys
import math

M , N = map(int , sys.stdin.readline().split())

check = [True if i > 1 else False for i in range(N+1)]
for num in range(2 ,N+1):
  if check[num] == True:
    for j in range(num*2 , N+1 , num):
      check[j] = False

for i in range(M,N+1):
  if check[i] == True:
    print(i)

python 모범답안

MAX = 1000000
check = [0]*(MAX+1)
check[0] = check[1] = True

for i in range(2, MAX+1):
    if not check[i]:
        j = i+i
        while j <= MAX:
            check[j] = True
            j += i
m, n = map(int,input().split())
for i in range(m, n+1):
    if check[i] == False:
        print(i)

0개의 댓글