Factorial of a large number in python

后端 未结 9 868
灰色年华
灰色年华 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:05

    If you need a short execution time and don't need the best possible accuracy, you can use an approximation formula, e.g. Stirling approximation

提交回复
热议问题