Approach 1: C(n,r) = n!/(n-r)!r!
Approach 2: In the book Combinatorial Algorithms by wilf, i have found this: C(n,r) can be written as C(n-1,r) + C
C(n-1,r) + C
unsigned long long ans = 1,a=1,b=1; int k = r,i=0; if (r > (n-r)) k = n-r; for (i = n ; k >=1 ; k--,i--) { a *= i; b *= k; if (a%b == 0) { a = (a/b); b=1; } } ans = a/b;