def crt(a_values, modulo_values):
 m = 1
 x = 0
 for modulo in modulo_values:
  m *= modulo
 for (m_i, a_i) in zip(modulo_values, a_values):
  M_i = (m // m_i)
  inv = inverse(M_i, m_i)
  x = ((x + ((a_i * M_i) * inv)) % m)
 return x

def crt ( a_values , modulo_values ) : m = 1 x = 0 for modulo in modulo_values : m *= modulo for ( m_i , a_i ) in zip ( modulo_values , a_values ) : M_i = ( m // m_i ) inv = inverse ( M_i , m_i ) x = ( ( x + ( ( a_i * M_i ) * inv ) ) % m ) return x
chinese remainder theorem .