Factorial of a large number in python

后端 未结 9 882
灰色年华
灰色年华 2020-12-29 12:32

Here\'s my approach to factorials:

def factorial(n):
    \'\'\'Returns factorial of n\'\'\'
    r = 1
    for i in range(1, n + 1):
        r *= i
    return         


        
9条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 13:24

    If you just need an approximation, Ramanujan's factorial approximation is supposed to be more accurate than Stirling's.

    If you need (or want) something precise, you might try GMP, the GNU Multiple Precision library. I've used it successfully for primality testing of large numbers in Python.

提交回复
热议问题