Skip to content

Instantly share code, notes, and snippets.

@paramsingh
Created August 20, 2018 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paramsingh/da9f3af15f92233a07e907cb8b89c723 to your computer and use it in GitHub Desktop.
Save paramsingh/da9f3af15f92233a07e907cb8b89c723 to your computer and use it in GitHub Desktop.
# A recursive function to find nth catalan number
def catalan(n):
# Base Case
if n <=1 :
return 1
# Catalan(n) is the sum of catalan(i)*catalan(n-i-1)
res = 0
for i in range(n):
res += catalan(i) * catalan(n-i-1)
return res
t = int(input())
for i in range(t):
x = int(input())
print(catalan(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment