
%\noindent \textbf{BigInteger Example}
\subsection{BigInteger Example}


\lstset{language=Java}
\begin{lstlisting}
//Catalan numbers
import java.awt.geom.*;
import java.util.*;
import java.awt.*;
import java.io.*;
import java.math.BigInteger;

class Catalan {
 public static void main(String[] args)
          throws IOException {
     new Catalan().run();
 }

 TreeMap<Integer, BigInteger> facts;

 public void run() throws IOException {
  Scanner cin = new Scanner(System.in);
  facts = new TreeMap<Integer,BigInteger>();

  while(true) {
   int n = cin.nextInt();
   if (n == 0) break;
    System.out.println( catalan(n).toString());
    //System.out.println( fact(n).toString());
  }
 }

 BigInteger catalan(int n) {
    return fact(2*n).divide(
                  fact(n+1).multiply(fact(n)));
 }

 BigInteger fact(int n) {
    BigInteger rv = BigInteger.valueOf(1);
    for(int i = 2; i <= n; ++i)
        rv = rv.multiply(BigInteger.valueOf(i));
    return rv;
 }
}
\end{lstlisting}
\normalsize

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../ref-doc"
%%% End:
