Java: Calculating binomial coefficient

后端 未结 3 1810
渐次进展
渐次进展 2021-01-07 11:30

I have the following programm calculating the binomial coefficient of two integers. But I want to change the programm, that it calculates and saves only the necessary coeffi

3条回答
  •  迷失自我
    2021-01-07 12:18

    What about this Code from this site

     private static long binomial(int n, int k)
        {
            if (k>n-k)
                k=n-k;
    
            long b=1;
            for (int i=1, m=n; i<=k; i++, m--)
                b=b*m/i;
            return b;
        }
    

提交回复
热议问题