![](https://media.vlpt.us/images/y7y1h13/post/3c954614-8949-43f9-8306-0cc252c611c4/image.png)
에라토스테네스 체를 사용해서 풀었다.
약수를 이용하면 시간을 많이 줄일 수 있다.
![](https://media.vlpt.us/images/y7y1h13/post/6c9fe534-a52f-48c1-b9b6-6495c78b75b4/image.png)
import math
k = 1000000
M, N = map(int, input().split())
a = [False, False] + [True] * 1000000
for i in range(2, int(math.sqrt(k+1))+1):
if a[i]:
for j in range(2*i, k+1, i):
a[j] = False
for i in range(M, N+1):
if a[i]:
print(i)