public static double nChooseK(int n, int k) {double d = 1;if (n<0 || k<0 || n<k) {d= Double.NaN;}else {int minnk = Math.min(n-k, k);int maxnk = Math.max(n-k, k);for (int i=maxnk; i<n; i++) {d *= i+1;}d /= factorial(minnk);}return d;}
public static double NChooseK(int n, int k){double d = 1;if (n < 0 || k < 0 || n < k){d = double.NaN;}else{int minnk = Math.Min(n - k, k);int maxnk = Math.Max(n - k, k);for (int i = maxnk; i < n; i++){d *= i + 1;}d /= Factorial(minnk);}return d;}