question: public static double logBinCoeff ( int n , int k ) { if ( k > n ) throw new IllegalArgumentException ( "Cannot compute (" + n + " choose " + k + " )" ) ; else if ( k == 0 || k == n ) return Math . log ( 1 ) ; double r = 0.0 ; for ( int d = 1 ; d <= k ; d ++ ) r += Math . log ( n - ( k - d ) ) - Math . log ( d ) ; return r ; }
target:  Returns the log of n choose k. Linear time computation.