Calculates sum of smallest number of multiplactions for each number up to and including n. >>> solution(1) 0 >>> solution(2) 1 >>> solution(14) 45 >>> solution(15) 50
(n: int = 200)
| 60 | |
| 61 | |
| 62 | def solution(n: int = 200) -> int: |
| 63 | """ |
| 64 | Calculates sum of smallest number of multiplactions for each number up to |
| 65 | and including n. |
| 66 | |
| 67 | >>> solution(1) |
| 68 | 0 |
| 69 | >>> solution(2) |
| 70 | 1 |
| 71 | >>> solution(14) |
| 72 | 45 |
| 73 | >>> solution(15) |
| 74 | 50 |
| 75 | """ |
| 76 | total = 0 |
| 77 | for i in range(2, n + 1): |
| 78 | max_length = 0 |
| 79 | while True: |
| 80 | nums = [1] |
| 81 | max_length += 1 |
| 82 | if solve(nums=nums, goal=i, depth=max_length): |
| 83 | break |
| 84 | total += max_length |
| 85 | return total |
| 86 | |
| 87 | |
| 88 | if __name__ == "__main__": |