What is the test to see if a number is divisible by seven?
arithmetic/tests.for.divisibility/seven Added material
Problem
What is the test to see if a number is divisible by seven?
Show solution
Take the last digit (n mod 10) and double it.
Take the rest of the digits (n div 10) and subtract the doubled last
digit from it.
The resulting number is divisible by 7 iff the original number
is divisible by 7.
Example: Take 53445
Subtract (53445 mod 10) * 2 from (53445 div 10)
- 5 * 2 + 5344
= 5334
533 - 2 * 4 = 525
52 - 5 * 2 = 42 which is divisible by 7
so 53445 is divisible by 7.
Additional material
Here are some divisibility tests for 7, taken from Martin Gardner's
_Unexpected_Hanging_ collection.
1. Take the digits of the number in reverse order, from right to left,
multiplying them successively by the digits 1, 3, 2, 6, 4, 5, repeating
with this sequence of multipliers as long as necessary. Add the products.
This sum is congruent to the original number mod 7.
2. [ Editor: the test given above: remove the last digit, double it,
subtract it from the truncated number, and repeat. ]
3. (L. Vosburgh Lyons) This is best explained by example.
2 | 35 | 94 | 06 | 17 | 88 | 39 From right to left, mark off digits in pairs
| | | | | |
2 | 0 | 3 | 6 | 3 | 4 | 4 Under each pair put down its excess over a
multiple of 7
3 4 4 Break up the sequence of excesses into blocks
0 3 6 of 3, put them under each other and add each
2 of the three columns separately
-----------
3 7 12
3 0 5 Replace each number by its excess over a
multiple of 7
|
2 | 5 Record the excess of 30 on the left,
| the excess of 05 on the right
Finally, subtract the left digit from the right digit (in this case we
get 5 - 2 = 3); the result is congruent to the original number mod 7.
4. Partition the number into three-digit sections, starting at the
right. Alternately add and subtract these sections, starting at the
right. The result is congruent to the original number mod 7.
Example: 61671142 -> 142 - 671 + 61 = -468 [Editor: "-148" in the
original; 142 - 671 + 61 = -468].
Gardner lists many references, including the following.
Leonard Eugene Dickson, "Criteria of Divisibility by a Given Number,"
_History_of_the_Theory_of_Numbers_ (New York: Chelsea Publishing, 1952),
Vol. I, Chapter 12, pp. 337-46.
E. A. Maxwell, "Division by 7 or 13," _Mathematical_Gazette_, Vol. 49,
February 1965, p. 84.
Henri Feiner, "Divisibility Test for 7," _The_Mathematics_Teacher_,
Vol. 58, April 1965, pp. 311-12.
-- Timothy Chow <tchow@math.lsa.umich.edu>
[ Editor: from the rec.puzzles thread "Divisibility by 7", February
1996. ]
Well I don't have to divide the whole number, but I do end in a divide
by 7. But then you can't complain about it that much. After all, I'm
sure you end with a divide by 3 in the test for divisibility by 3.
Anyway, here is the method. Take your number (eg 3,141,592,654 )
Alternately add and subtract them :
+654
-592
+141
- 3
-----
200
So if 200 is divisible by 7, then so is the original number.
This also works for 11 and 13, as 7*11*13 is 1001.
-- David Norman <David@ellought.demon.co.uk>
Here is one way: start with the first digit in the number and find the
remainder by 7 (so 7-9 becomes 0-2). Now repeat the following step
until there are no further digits:
If there are any further digits, multiply the number you have by 3 and
add the next digit, then find the remainder by 7.
The end result is the remainder by 7 of the whole number. If this is
0, the number divides evenly by 7.
The largest intermediate result you will have is 27 (6x3+9), so you
will just have to be able to find the remainder by 7 of any number up
to this.
Example: the number 92845673947 is handled like this:
9 reduces to 2
2x3+2 = 8, reduces to 1
1x3+8 = 11, reduces to 4
4x3+4 = 16, reduces to 2
2x3+5 = 11, reduces to 4
4x3+6 = 18, reduces to 4
4x3+7 = 19, reduces to 5
5x3+3 = 18, reduces to 4
4x3+9 = 21, reduces to 0
0x3+4 = 4
4x3+7 = 19, reduces to 5
Hence the remainder by 7 of 92845673947 is 5.
The methods for testing divisibility by other numbers are actually
similar: multiply the current value by a constant and add the next
digit, then reduce the result. The constant is found by considering
the remainder of 10 by the divisor. For 2 and 5 the constant is 0, so
only the last digit matters. For 3 and 9 the constant is 1, so summing
the digits and then reducing gets the result. And so on.
-- Torben AEgidius Mogensen <torbenm@diku.dk>