import java.math.*; import java.io.*; public class Binomial { private static BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) ); // This is the classic, recursive implementation of a function // that computed the nth Fibonacci number (given n) public static int binomial(int n, int k) { if(n < k) return 0; if(n == k) return 1; if(k == 1) return n; if(k == 0) return 1; return binomial(n-1, k) + binomial(n-1, k-1); } public static void main(String[] args) { int n; long time, newTime, answer; // Prompt the user System.out.println("Type two positive integers." ); try{ // Read a line of text from the user. String input = stdin.readLine(); // converts a String into an int value n = Integer.parseInt( input ); // Read a line of text from the user. input = stdin.readLine(); // converts a String into an int value int k = Integer.parseInt( input ); time = System.currentTimeMillis(); answer = binomial(n, k); newTime = System.currentTimeMillis(); System.out.println("The binomial number is "+ answer); System.out.println("It took " + (newTime-time) + " milliseconds to compute it."); } catch(java.io.IOException e) { System.out.println(e); } } // end of main } // end of class