Algorithm for Calculating Binomial Coefficient

前端 未结 5 2001
别跟我提以往
别跟我提以往 2020-12-10 05:30

I need a way of calculating combinations without running out of memory. Here\'s what i have so far.

public static long combination(long n, long k) // nCk
{
          


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 05:53

    Just for the sake of completion: the standard C math library has implementations of both Γ and lnΓ (called tgamma and lgamma), where

    Γ(n) = (n-1)!

    The library computation is certainly faster and more accurate than summing logarithms. For a lot more information, see Wikipedia and Mathworld.

提交回复
热议问题