fork download
  1. def factorial(n):
  2. res = 1
  3. for x in range(2, n+1): res *= x
  4. return res
  5.  
  6. def solve(n):
  7. if n <= 2: return None
  8. if n == 7: return [2520, 1260, 630, 315, 252, 56, 7]
  9.  
  10. res = []
  11. f = factorial(n)
  12. x = f
  13.  
  14. for _ in range(n - 2):
  15. x = x >> 1
  16. res.append(x)
  17.  
  18. for y in range(1, x):
  19. if f % y == 0 and f % (x-y) == 0:
  20. res.append(x-y)
  21. res.append(y)
  22. return res
  23.  
  24. raise Exception(f'Failed to solve for {n}')
  25.  
  26. for x in range(3, 16):
  27. cur = solve(x)
  28. print(x, sum(cur), factorial(x), cur)
Runtime error #stdin #stdout #stderr 0.13s 22840KB
stdin
Standard input is empty
stdout
3 6 6 [3, 2, 1]
4 24 24 [12, 6, 4, 2]
5 120 120 [60, 30, 15, 12, 3]
6 720 720 [360, 180, 90, 45, 40, 5]
7 5040 5040 [2520, 1260, 630, 315, 252, 56, 7]
8 40320 40320 [20160, 10080, 5040, 2520, 1260, 630, 560, 70]
9 362880 362880 [181440, 90720, 45360, 22680, 11340, 5670, 2835, 2520, 315]
10 3628800 3628800 [1814400, 907200, 453600, 226800, 113400, 56700, 28350, 14175, 12600, 1575]
stderr
Traceback (most recent call last):
  File "./prog.py", line 27, in <module>
  File "./prog.py", line 24, in solve
Exception: Failed to solve for 11