Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculator(N):
- if N == 1: return 0
- if N == 2: return 1
- if N == 3: return 1
- A = ['.' for i in range(N + 1)]
- A[0] = 0
- A[1] = 0
- A[2] = 1
- for i in range(3, N + 1):
- if i % 2 == 0: a = i // 2
- else: a = False
- if i % 3 == 0: b = i // 3
- else: b = False
- if a and b:
- A[i] = min(A[i - 1], A[a], A[b]) + 1
- elif a:
- A[i] = min(A[i - 1], A[a]) + 1
- elif b:
- A[i] = min(A[i - 1], A[b]) + 1
- else:
- A[i] = A[i - 1] + 1
- return A[-1]
- n = int(input())
- print(calculator(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement