Added cache to factorial calculation

Caching the BigInt calculation gives speedup, as don’t have to go to
BigInt each time.