M이상 N이하의 소수를 모두 출력하는 프로그램을 작성하시오.
예제 입력1
3 16
예제 출력1
3 5 7 11 13
import math
def check(num):
if num == 1:
return False
for i in range(2, int(math.sqrt(num))+1):
if num % i == 0:
return False
return True
m, n = map(int, input().split())
for j in range(m, n+1):
if check(j):
print(j)
🧷(나만 알아듣는) 추가설명
math.sqrt(x) vs x ** 0.5
제곱근을 x ** 0.5로 한사람이 많아서 찾아보니
math.sqrt(x) is significantly faster than x ** 0.5
x ** 0.5 =
10 loops, best of 3: 156 ms per loop
math.sqrt(x) =
10 loops, best of 3: 91.1 ms per loop
math.sqrt(x)가 거희 1.5배 빠르다