MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_076/sol1.py:19–51  ·  view source on GitHub ↗

Returns the number of different ways the number m can be written as a sum of at least two positive integers. >>> solution(100) 190569291 >>> solution(50) 204225 >>> solution(30) 5603 >>> solution(10) 41 >>> solution(5) 6 >>> solution(3) 2

(m: int = 100)

Source from the content-addressed store, hash-verified

17
18
19def solution(m: int = 100) -> int:
20 """
21 Returns the number of different ways the number m can be written as a
22 sum of at least two positive integers.
23
24 >>> solution(100)
25 190569291
26 >>> solution(50)
27 204225
28 >>> solution(30)
29 5603
30 >>> solution(10)
31 41
32 >>> solution(5)
33 6
34 >>> solution(3)
35 2
36 >>> solution(2)
37 1
38 >>> solution(1)
39 0
40 """
41 memo = [[0 for _ in range(m)] for _ in range(m + 1)]
42 for i in range(m + 1):
43 memo[i][0] = 1
44
45 for n in range(m + 1):
46 for k in range(1, m):
47 memo[n][k] += memo[n][k - 1]
48 if n > k:
49 memo[n][k] += memo[n - k - 1][k]
50
51 return memo[m][m - 1] - 1
52
53
54if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected