[net.math] divisibility by 7

ark@rabbit.UUCP (08/25/83)

To tell if an integer n is divisible by 7, repeat the following:

	n := floor(n / 10) - 2 * (n mod 10)

You will evetually get a number that you can check at a glance.
For instance:

	142857

	14285 - 14 = 14271
	1427 - 2 = 1425
	142 - 10 = 132
	13 - 4 = 9

9 is not divisible by 7, so neither is 142857.

jim@ism780.UUCP (Jim Balter) (08/25/83)

That's cute!  And it's easy to prove.  It is equivalent to saying that
n mod 7 = 0  iff  (floor(n/10) - 2*(n mod 10)) mod 7 = 0.

Say n = 7*x = 10*a + b (a and b integers).
Then floor(n/10) - 2*(n mod 10) = a - 2*b.
By algebra  a - 2*b = 21*a - 14*x = 7*(3*a-2*x).
So, n mod 7 = 0  iff  x is an integer  iff  a - 2*b is divisible by 7.

I like your sample (but hardly random) number.  Note for instance

	142857*1 =  142857
	142857*3 =  428571
	142857*2 =  285714
	142857*6 =  857142
	142857*4 =  571428
	142857*5 =  714285

--------