I am writing a Python code to generate Catalan numbers using the mathematical formula given here:
C(0) = 1 and C(n) = (2(2n − 1) / (n + 1)) * C(n − 1) per this website here. (https://rosettacode.org/wiki/Catalan_numbers)
However, when I am writing it in python as a function, it gives me false results.
eg: For 20 answer should be 6564120420.0 while my code gives me 344373768.
Here:
def catalan(cat_input):
if cat_input==0:
return 1
else:
return (((4*cat_input) - 2) / (cat_input + 1)) * (catalan(cat_input-1))
Can someone help me figure this out please ?