Mathematical division

let us assume two numbers A and B. Now A is not divisible by B.

mod = A%B
now (A + mod*(B-1)) is divisible by B. Why???

for example
A = 3
B=5
-> mod = A%B = 3%5 = 3;
-> A + mod*(B-1) = 3 + 3*(5-1) = 3 + 12 = 15 which is divisible by B.

another example:
A = 17
B = 12
mod = 17%12 = 5
A + mod * (B-1) = 17 + 5*(12-1) = 17 + 5*11 = 72 which is divisible by B = 12.

Try for any example and this is true. But i want to know why.?

How much do you understand about modular arithmetic?

read this Art of Problem Solving

Because you are basically doing A+A\times -1 = 0

1 Like

mod = A%B.

And A can be written as kB + mod ,as mod is the remainder obtained when A is divided by B.
A+(mod )(B-1)= k
B +mod +mod (B-1) = kB + (mod)*(B) = (k+mod)*B. which is divisible by B.

1 Like