4948번

김범주·2022년 7월 25일
0

백준 파이썬

목록 보기
23/29
post-thumbnail

정답

def prime(x):
  if x == 1:
    return False
  for i in range(2, int(x**0.5) + 1):
    if x % i == 0:
      return False
  return True 

num_list = []
all = list(range(2, 246912))

for i in all:
  if prime(i):
    num_list.append(i)

n = int(input())

while True:
  count1 = 0
  if n == 0:
    break
  for i in num_list:
    if n < i <= 2*n:
      count1 += 1
  print(count1)
  n = int(input())    

원래 숫자 범위를 정해주지 않고 했으나 시간초과가 나와서 수정, 블로깅 해보니 숫자가 그렇게 크지 않아 저 정도의 숫자는 그냥 해주는게 낫다고...

profile
개발꿈나무

0개의 댓글