def inverseOf(a:int, n:int): """ find the inverse of a in the ring of Z base n (in mod n) a:int = number which inverse is in question n:int = mod (ring of Z) base """ if pulv.gcd(n,a).value != 1 : raise ValueError("the number is not relatively prime to the mod base!") else: result = pulv.gcd(n,a).t while result <= 0: # keep adding base n until the inverse result is positive result += n return result
def test_longer_remainder_gcd_reversed_params(self): """ test the scenario of product of primes gcd but the parameters are on reversed order """ result = pulverizer.gcd(91, 221) # assert self.assertEqual([result.value, result.s, result.t], [13, 5, -2], "reversed order incorrect")
def test_longer_remainder_gcd(self): """ the scenario is for the gcd of two numbers which directly product of two primes. """ result = pulverizer.gcd(221, 91) # assert self.assertEqual([result.value, result.s, result.t], [13, -2, 5], "longer gcd linear comb incorrect")
def test_divisior_as_first_param_gcd(self): """ the scenario is for the divisor as first param """ # set result = pulverizer.gcd(50, 400) # assert self.assertEqual([result.value, result.s, result.t], [50, 1, 0], "the result list order is incorrect")
def test_divisor_as_gcd(self): """ the scenario is if the divisor is the gcd in the second parameter. """ # setup result = pulverizer.gcd(400, 20) # assert self.assertEqual(result.value, 20, "value is not match the gcd") self.assertEqual([result.s, result.t], [0, 1], "the s and t coefficients is not correct")