According to the wiki catalan definition from wiki, I see the expression below:
I can understand the first two expressions, but really confused about the third one. The pi symbol stands for the multiply. Does the expression mean the code below:
for (int i = 2; i < n + 1; i++) {
sum *= (n + i)/i;
}
My code is below
public class Test {
public int getCatalan(int n) {
//Catalan Number = (2n)!/(n+1)!*n!
int product = 1;
if (n == 1)
return 1;
for (int i = 2; i < n + 1; i++) {
product *= (n+i)/i;
}
return product;
}
public static void main(String[] args) {
Test test = new Test();
for (int i = 1;i < 7; i++) {
System.out.println("when i=" + i + " its catalan number is "+ test.getCatalan(i));
}
}
}
and I get the result is totally wrong
Anyone help me?