卡特兰数 递推公式:h(n)=h(n-1)*(4*n-2)/(n+1);
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(String args[]) { 7 Scanner cin = new Scanner(System.in); 8 BigInteger[] c = new BigInteger[101]; 9 c[1] = BigInteger.valueOf(1); 10 c[2] = BigInteger.valueOf(2); 11 for (int i = 3; i <= 100; i++) { 12 BigInteger x1 = BigInteger.valueOf(4*i-2); 13 BigInteger x2 = BigInteger.valueOf(i+1); 14 c[i]=c[i-1].multiply(x1).divide(x2); 15 } 16 17 while (cin.hasNext()) { 18 int N = cin.nextInt(); 19 if (N==-1) 20 break; 21 else 22 System.out.println(c[N]); 23 } 24 } 25 }