forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8.py
More file actions
20 lines (17 loc) ยท 683 Bytes
/
8.py
File metadata and controls
20 lines (17 loc) ยท 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import math
# M๊ณผ N์ ์
๋ ฅ๋ฐ๊ธฐ
m, n = map(int, input().split())
array = [True for i in range(1000001)] # ์ฒ์์ ๋ชจ๋ ์๊ฐ ์์(True)์ธ ๊ฒ์ผ๋ก ์ด๊ธฐํ
array[1] = 0 # 1์ ์์๊ฐ ์๋
# ์๋ผํ ์คํ
๋ค์ค์ ์ฒด ์๊ณ ๋ฆฌ์ฆ
for i in range(2, int(math.sqrt(n)) + 1): # 2๋ถํฐ n์ ์ ๊ณฑ๊ทผ๊น์ง์ ๋ชจ๋ ์๋ฅผ ํ์ธํ๋ฉฐ
if array[i] == True: # i๊ฐ ์์์ธ ๊ฒฝ์ฐ (๋จ์ ์์ธ ๊ฒฝ์ฐ)
# i๋ฅผ ์ ์ธํ i์ ๋ชจ๋ ๋ฐฐ์๋ฅผ ์ง์ฐ๊ธฐ
j = 2
while i * j <= n:
array[i * j] = False
j += 1
# m๋ถํฐ n๊น์ง์ ๋ชจ๋ ์์ ์ถ๋ ฅ
for i in range(m, n + 1):
if array[i]:
print(i)