// Big_num.java  test java.math.BigInteger class

import java.math.BigInteger;

class Big_num
{
  Big_num() // constructor
  {
    BigInteger a = new BigInteger("12345678901234567890");
    BigInteger b = new BigInteger("2345678901234567890");
    BigInteger c;
 
    System.out.println("Big_num");
    c=a.add(b);
    System.out.println("a="+a.toString());
    System.out.println("b="+b.toString());
    System.out.println("a+b=c="+c.toString());

    // factorials
    BigInteger f[] = new BigInteger[49];
    f[0]=new BigInteger("1");
    System.out.println("0! = "+f[0]);
    f[1]=f[0]; 
    System.out.println("1! = "+f[1]);
    f[2]=f[1].add(f[1]);
    System.out.println("2! = "+f[2]);
    for(int i=3; i<49; i++)
    {
      BigInteger g = new BigInteger(Integer.toString(i));
      f[i]=f[i-1].multiply(g);
      System.out.println(i+"! = "+f[i]);
    }
    System.out.println();
    for(int i=4; i<49; i=i+2)
    {
      System.out.println(i+" choose "+i/2+" = "+(f[i].divide(f[i/2].multiply(f[i/2]))));
    }
    System.out.println();
    for(int i=1; i<65; i++)
    {
      BigInteger p = new BigInteger("2");
      for(int j=1; j<i; j++) p = p.multiply(new BigInteger("2"));
      System.out.println("2^"+i+" = "+p);
    }
    System.out.println();
    for(int i=1; i<8; i++)
    {
      int r = 2;
      for(int k=1; k<i; k++) r=r*2;
      BigInteger q = new BigInteger("2");
      for(int j=1; j<r; j++) q = q.multiply(new BigInteger("2"));
      System.out.println("2^(2^"+i+") = "+q);
    }
    System.out.println();
    for(int i=1; i<8; i++)
    {
      BigInteger q = new BigInteger("2");
      for(int j=1; j<i; j++) q = q.multiply(new BigInteger("2"));
      BigInteger q2 = q.divide(new BigInteger("2"));      
      System.out.println(q+" choose "+q2+" = "+(ff(q).divide(
                         ff(q2).multiply(ff(q2)))));
    }
    System.out.println();
  }

  static BigInteger ff(BigInteger n)
  {
    if(n.compareTo(BigInteger.ONE)<=0) return BigInteger.ONE;
    return n.multiply(ff(n.subtract(BigInteger.ONE)));  
  }

  public static void main (String[] args) // "main" required
  {
    new Big_num();
  }
}
