9/11/17

Algorithm with congruence SF

Stephen Froggatt  indicates in Math Forum an equation, it can help in finding remainders Divisibility Rules to 50 and Beyond.
His explanation is as follow (divisibility by 7 in decimal):
Assume, that 10b+a = 7k.
Then b+5a = b+5(7k-10b) = 35k-49b = 7(5k-7b).
But where are 5 get from?

There exists a numbers M, K and formula
M*P - K*D = 1
for base P and divisor D. Let M is as small positive as possible.
Then the number N is split into two parts, b is N with cutting least significant digit off, and this digit a.
This equation is equivalent to congruence
M*P = 1 (mod D)
Such case
N*M = (b*P+a)M = b(P*M)+a*M = b*1 + a*M = b+aM (mod D)
In mentioned example we check: 10=3 (7), 20=-1 (7), 30=2 (7), 40=5 (7), 50=1(7) it is this, M=5.

Number N is divisible by D iff  b+M*a is divisible by D.

Congruence allows the second formulae, when M is bigger than half D. Simply decrease M by D:

Number N is divisible by D iff  b+(M-D)*a is divisible by D.


Upgrade [SF-]
We can use congruence
M*P = -1 (mod D)
Such case there is
N*M = -b+aM = -(b-aM) (mod D)


This method doesn't detect quotient N / D.