Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. x = int(input())
  2. a = []
  3. if x == 1:
  4. print("0")
  5. elif x == 2:
  6. print("1")
  7. elif x == 3:
  8. print("1")
  9. else:
  10. a = [0] * (x + 1)
  11. a[1] = 0
  12. a[2] = 1
  13. a[3] = 1
  14. for i in range(4, x + 1):
  15. a[i] = a[i-1] + 1
  16. if i % 3 == 0:
  17. if a[i] > a[i//3] + 1:
  18. a[i] = a[i//3] + 1
  19. if i % 2 == 0:
  20. if a[i] > a[i//2] + 1:
  21. a[i] = a[i//2] + 1
  22. print(a[x])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement