Skip to content
Related Articles

Related Articles

Improve Article

Python | sympy.crt() method

  • Last Updated : 17 Sep, 2019

With the help of sympy.crt() method, we can implement the Chinese Remainder Theorem in SymPy.

Syntax: crt(m, v)

Parameter:
m – It denotes a list of integers.
v – It denotes a list of integers.

Returns: Returns a tuple of integers where the first element is the required result.

Example #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]))

Output:

Result of the Chinese Remainder Theorem = 31 

Example #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]))

Output:

Result of the Chinese Remainder Theorem = 639985 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :