counting combinations and permutations efficiently

后端 未结 13 1987
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 12:38

I have some code to count permutations and combinations, and I\'m trying to make it work better for large numbers.

I\'ve found a better algorithm for permutations th

13条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 13:11

    You could input two integers and import math library to find the factorial and then apply the nCr formula

    import math
    n,r=[int(_)for _ in raw_input().split()]
    f=math.factorial
    print f(n)/f(r)/f(n-r)
    

提交回复
热议问题