definverseMod(number, mod): total = 1 for i in range(mod): if (total%number) == 0: return total/number total = total + mod returnFalse
defchineseRemainingTheory(remainList, modList): inverserModList = [] allProduct = 1 for i in modList: allProduct = allProduct * i result = 0 for index in range(len(remainList)): products = (allProduct/modList[index]) inverse = inverseMod(products%modList[index], modList[index]) result = result + (inverse * products * remainList[index]) return result