algorithmpython-3.xdiscrete-mathematicsbinomial-coefficients

Smart algorithm for finding the divisors of a binomial coefficient


I'm interested in tips for my algorithm that I use to find out the divisors of a very large number, more specifically "n over k" or C(n, k). The number itself can range very high, so it really needs to take time complexity into the 'equation' so to say.

The formula for n over k is n! / (k!(n-k)!) and I understand that I must try to exploit the fact that factorials are kind of 'recursive' somehow - but I havent yet read too much discrete mathematics so the problem is both of a mathematical and a programming nature.

I guess what I'm really looking for are just some tips heading me in the right direction - I'm really stuck.


Solution

  • First you could start with the fact that : C(n,k) = (n/k) C(n-1,k-1).
    You can prouve that C(n,k) is divisible by n/gcd(n,k).
    If n is prime then n divides C(n,k).
    Check Kummer's theorem: if p is a prime number, n a positive number, and k a positive number with 0< k < n then the greatest exponent r for which p^r divides C(n,k) is the number of carries needed in the subtraction n-k in base p.

    Let us suppose that n>4 :