📜  Python| sympy.crt() 方法

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

Python| sympy.crt() 方法

借助sympy.crt()方法,我们可以在 SymPy 中实现中国剩余定理。

示例 #1:

# import crt() method from sympy
from sympy.ntheory.modular import crt
  
m = [5, 7]
v = [1, 3]
  
# Use crt() method 
crt_m_v = crt(m, v) 
      
print("Result of the Chinese Remainder Theorem = {} ".format(crt_m_v[0]))

输出:

Result of the Chinese Remainder Theorem = 31 

示例 #2:

# import crt() method from sympy
from sympy.ntheory.modular import crt
  
m = [99, 97, 95]
v = [49, 76, 65]
  
# Use crt() method 
crt_m_v = crt(m, v) 
      
print("Result of the Chinese Remainder Theorem = {} ".format(crt_m_v[0]))

输出:

Result of the Chinese Remainder Theorem = 639985