def test_crt_without_coprime(self): v = random.randint(10, 10000000000) n = random.randint(1, 100) remainders = [] moduli = [] for i in range(n): mod = random.randint(2, 100000000) remainders.append(v % mod) moduli.append(mod) lcm = reduce(gmpy2.lcm, moduli) res = number.crt(remainders, moduli, False) self.assertEqual(res, (v % lcm, lcm))
def test_crt_coprime(self): v = random.randint(10, 10000000000) n = random.randint(1, 100) remainders = [] moduli = [] lcm = 1 for i in range(n): while True: mod = random.randint(2, 100000000) g = gmpy2.gcd(mod, lcm) if g == 1: break remainders.append(v % mod) moduli.append(mod) lcm *= mod res = number.crt(remainders, moduli) self.assertEqual(res, (v % lcm, lcm))
def test_crt_coprime(self): v = random.randint(10, 10000000000) n = random.randint(1, 100) remainders = [] moduli = [] lcm = 1 for i in range(n): while True: mod = random.randint(2, 100000000) g = gmpy2.gcd(mod, lcm) if g == 1 : break remainders.append(v % mod) moduli.append(mod) lcm *= mod res = number.crt(remainders, moduli) self.assertEqual(res, (v % lcm, lcm))