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

Function solution

project_euler/problem_190/sol1.py:23–44  ·  view source on GitHub ↗

Calculate sum of |_ P_m _| for m from 2 to n. >>> solution(2) 1 >>> solution(3) 2 >>> solution(4) 4 >>> solution(5) 10

(n: int = 15)

Source from the content-addressed store, hash-verified

21
22
23def solution(n: int = 15) -> int:
24 """
25 Calculate sum of |_ P_m _| for m from 2 to n.
26
27 >>> solution(2)
28 1
29 >>> solution(3)
30 2
31 >>> solution(4)
32 4
33 >>> solution(5)
34 10
35 """
36 total = 0
37 for m in range(2, n + 1):
38 x1 = 2 / (m + 1)
39 p = 1.0
40 for i in range(1, m + 1):
41 xi = i * x1
42 p *= xi**i
43 total += int(p)
44 return total
45
46
47if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected