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)
| 21 | |
| 22 | |
| 23 | def 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 | |
| 47 | if __name__ == "__main__": |