Fast n choose k mod p for large n?
What I mean by "large n" is something in the millions. p is prime. I've tried http://apps.topcoder.com/wiki/display/tc/SRM+467 But the function seems to be incorrect (I tested it with 144 choose 6 mod 5 and it gives me 0 when it should give me 2) I've tried http://online-judge.uva.es/board/viewtopic.php?f=22&t=42690 But I don't understand it fully I've also made a memoized recursive function that uses the logic (combinations(n-1, k-1, p)%p + combinations(n-1, k, p)%p) but it gives me stack overflow problems because n is large I've tried Lucas Theorem but it appears to be either slow or