find the smallest remainder

xiaodong

New member
Joined
Dec 4, 2020
Messages
1
K, J = positive integer

please write a formula to find the smallest Z

2*K + 5*J + Z = 100 (This is an example, 2, 5, 100 can be random)
 
Look into the Chinese Remainder theorem and it's use in solving linear Diophantine equations.
 
I would use the largest multiply of the larger number (5) without going over the sum (in this case 100) and then add on the largest multiple of the smaller number (2) still without going over the total sum and then figure out what z should be.

In you example, 5 goes evenly into 100 so the answer will 2*0 + 5*20 + 0 =100. So z=0

If you had 4k + 7k = 104 then figure out 1st how many times 7 goes into 104. That answer is 14. Now 7*14 is 98 which is 6 away from 104. That 6 can have just one 4 subtracted from it leaving 2 left over. That is 4*1 + 7*14 + 2 = 104, so z=2.
 
Top