Skip to content

Commit

Permalink
1로 만들기 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezidayzi committed Mar 6, 2022
1 parent a572ec6 commit 53ec81e
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys
n = int(sys.stdin.readline().rstrip())

d = [0] * (n+1)

for i in range(2, n+1):
d[i] = d[i-1] + 1

if i % 2 == 0:
d[i] = min(d[i], d[i//2] + 1)
if i % 3 == 0:
d[i] = min(d[i], d[i//3] + 1)
if i % 5 == 0:
d[i] = min(d[i], d[i//5] + 1)

print(d[n])

0 comments on commit 53ec81e

Please sign in to comment.