Problems > Catalan Number

Catalan Number

Difficulty: 1400 2000 ms 128 MB

math combinatorics

Print the N-th Catalan number CN (C0 = 1, C1 = 1, C2 = 2, C3 = 5, ...). It counts balanced bracket strings, binary trees, and much more.

Input: one integer N.

Output: CN exactly (it fits in 64 bits for N ≤ 33).

Constraints:

  • 0 ≤ N ≤ 33

Sample Tests

Input 1
3
Output 1
5
Input 2
0
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.