This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another. And, no two segments are allowed to intersect.
It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?
It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?
InputEach line of the input file will be a single positive number n, except the last line, which is a number -1. You may assume that 1 <= n <= 100.
OutputFor each n, print in a single line the number of ways to connect the 2n numbers into pairs.
Sample Input
2 3 -1
Sample Output
2 5
卡兰特数套公式
java大法好啊!
1 import java.util.*; 2 import java.math.*; 3 public class Main 4 { 5 public static BigInteger TM; 6 public static void main(String[] args) 7 { 8 Scanner sc=new Scanner(System.in); 9 while(sc.hasNext()) 10 { 11 int n=sc.nextInt(); 12 if(n==-1) 13 break; 14 int a,b; 15 TM=BigInteger.ONE; 16 TM=TM.multiply(BigInteger.valueOf(2)); 17 if(n==1) 18 { 19 System.out.println(1); 20 continue; 21 } 22 if(n==2) 23 { 24 System.out.println(2); 25 continue; 26 } 27 for(int i=3;i<=n;i++) 28 { 29 a=4*i-2; 30 b=i+1; 31 TM=TM.multiply(BigInteger.valueOf(a)); 32 TM=TM.divide(BigInteger.valueOf(b)); 33 34 } 35 System.out.println(TM); 36 } 37 } 38 }