본문 바로가기

algorithm

[python] 카탈랑 수(Catalan number)

 

Catalan number - Wikipedia

From Wikipedia, the free encyclopedia Jump to navigation Jump to search Recursive integer sequence In combinatorial mathematics, the Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively def

en.wikipedia.org

 

 

카탈랑 수(Catalan number)란?

Cn = 2n! / n! (n+1)! 형태의 점화식을 갖는 수열로 조합론에서 꽤 빈번하게 등장한다고 한다.

따라서 카탈랑 수를 python 코드로 구현할 경우 아래와 같다.

import math
num = int(input())


def catalan(n):
    return math.factorial(2 * n) // (math.factorial(n) * math.factorial(n + 1))


print(catalan(num))