Ad
  • Custom User Avatar

    have you tried memoization?

    Are you offering to memoize the function randomly for different values of n and p hoping that this will help somehow?

  • Custom User Avatar

    If you have to use so much factorials, have you tried memoization? The cleanest solutions take a look at the math first though.