-3

I want to store factorials of numbers in range 1 to 200,000 but as the factorials for larger numbers are very big my program is running out of space. Is there any way I can store them in a array?

My code:

factorial_of_numbers = []
factorial_of_numbers = [factorial_of_numbers[-1] for x in range(0, 200001) if not factorial_of_numbers.append(x*factorial_of_numbers[-1] if factorial_of_numbers else 1)]

With this approach I am only able to store factorial till 10,000.

Can anyone suggest any other approach or how to store big factorials?

khelwood
  • 55,782
  • 14
  • 81
  • 108

1 Answers1

0

This only took me about a minute to run:

>>> factorials = [1]
>>> for _ in range(200000):
...     factorials.append(factorials[-1] * (len(factorials) + 1))
...
>>> factorials[-1]
2840464893194083513077942336...(VERY LONG NUMBER)
Samwise
  • 68,105
  • 3
  • 30
  • 44