Chinese remainder theorem
def inv(a,m):
a=a%m
for i in range(1,m):
if((a*i)%m==1):
return i
def funcMax(num,rem):
prod=1
for i in num:
prod*=i
result=0
if(len(num)==len(rem)):
for i in range(len(num)):
pp=prod//num[i]
result=result+(rem[i]*pp*inv(pp,num[i]))
return result%prod
print(funcMax([3,4,5],[2,3,1]))
0 Comments