forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path5.py
More file actions
27 lines (23 loc) ยท 761 Bytes
/
5.py
File metadata and controls
27 lines (23 loc) ยท 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
n = int(input())
ugly = [0] * n # ๋ชป์๊ธด ์๋ฅผ ๋ด๊ธฐ ์ํ ํ
์ด๋ธ (1์ฐจ์ DP ํ
์ด๋ธ)
ugly[0] = 1 # ์ฒซ ๋ฒ์งธ ๋ชป์๊ธด ์๋ 1
# 2๋ฐฐ, 3๋ฐฐ, 5๋ฐฐ๋ฅผ ์ํ ์ธ๋ฑ์ค
i2 = i3 = i5 = 0
# ์ฒ์์ ๊ณฑ์
๊ฐ์ ์ด๊ธฐํ
next2, next3, next5 = 2, 3, 5
# 1๋ถํฐ n๊น์ง์ ๋ชป์๊ธด ์๋ค์ ์ฐพ๊ธฐ
for l in range(1, n):
# ๊ฐ๋ฅํ ๊ณฑ์
๊ฒฐ๊ณผ ์ค์์ ๊ฐ์ฅ ์์ ์๋ฅผ ์ ํ
ugly[l] = min(next2, next3, next5)
# ์ธ๋ฑ์ค์ ๋ฐ๋ผ์ ๊ณฑ์
๊ฒฐ๊ณผ๋ฅผ ์ฆ๊ฐ
if ugly[l] == next2:
i2 += 1
next2 = ugly[i2] * 2
if ugly[l] == next3:
i3 += 1
next3 = ugly[i3] * 3
if ugly[l] == next5:
i5 += 1
next5 = ugly[i5] * 5
# n๋ฒ์งธ ๋ชป์๊ธด ์๋ฅผ ์ถ๋ ฅ
print(ugly[n - 1])