Is there an efficient way to find the number n, given a number N (may be as large as 10^18) which is equal to nCr for some n and r ? How do we find the corresponding minimum value of n? for instance
f(20)=6 (20=6C3)
f(21)= 7 (21=7C2)
f(22)= 22 (22=22C1)
To find minimum n is same as to find maximum r with
r<=n/2
. SincenCr
is bounded from below with(2r)Cr=(2r)!/r!
, number of r's to check is finite. For10^18
maximum r is 31, since64C32=1.8*10^18
.To find n, for given r, that satisfies N=nCr, it is possible to check is
N*r!
of formn*(n-1)*...*(n-r+1)
. n is near(N*r!)^(1/r) + r/2
. I think with few checks it can be tested.Update:
Simple python implementation:
prints: