Thursday, December 13, 2018

[Spoj] Catalan Numbers

Author            : Dipu Kumar Mohanto 
                    CSE, Batch - 6
                    BRUR.
Problem Statement : Catalan Numbers 
Source            : Spoj
Category          : Combinatorics
Algorithm         : Catalan Number, n'th Catalan Number without mod
Verdict           : Accepted
catalan = [0]*5005
 
catalan[0] = catalan[1] = 1;
for i in range(2, 5000+1, 1):
    catalan[i] = ((4*i - 2) * catalan[i-1]) // (i+1);
 
tc = int(input())
for tcase in range(tc):
    n = int(input())
    print(catalan[n])

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.