📜  Python| sympy.catalan() 方法

📅  最后修改于: 2022-05-13 01:54:57.813000             🧑  作者: Mango

Python| sympy.catalan() 方法

借助sympy.catalan()方法,我们可以在 SymPy 中找到加泰罗尼亚数字。它表示为——

   C_n = \frac{1}{n+1} \binom{2n}{n}

示例 #1:

# import sympy 
from sympy import * n = 4
print("Value of n = {}".format(n))
   
# Use sympy.catalan() method 
nth_catalan = catalan(n)  
      
print("Value of nth catalan number : {}".format(nth_catalan))  

输出:

Value of n = 4
Value of nth catalan number : 14

示例 #2:

# import sympy 
from sympy import * n = 15
print("Value of n = {}".format(n))
   
# Use sympy.catalan() method 
nth_catalan = catalan(n)  
      
print("Value of nth catalan number : {}".format(nth_catalan))  

输出:

Value of n = 15
Value of nth catalan number : 9694845