A quickie, I hope!.
I’m hopping that one of you has a way to assertiain if a whole positive integer is divisible by 7.
1!, 2,3,4,5,10,11 are fairly easy, for instance 11 look at the number and split it up into it’s odd and even numbered components and compare. If they’re identical or the difference is divisible by 11 you’re on a winner.
To parahrase myself can I look at a number and analyse it’s structure without long division and tell if it’s a multiple of seven?
Good people your help is, as always, invaluable.
Peter Underhill
Google divisibilty test:
Moving thread from Great Debates to General Questions.
Basically, there is no easy way to determine divisibility by 7 like there is for other small numbers. Usually just dividing by 7 will get you an answer just as fast as any other method. If you really don’t like dividing though, you can use the following:
For numbers of 3 digits or less, you can subtract twice the unit digit from the other two digits: 392 is divisible by 7 since 39 - 22 = 35 is. If you don’t even like subtraction, you can add 5 times the unit digit to the other two: 392 -> 39 + 25 = 49, a multiple of 7. These work due to 21 and 49 being multiples of 7.
For 4-6 digit numbers, use the fact 1001 is divisible by 7: write in the thousands separator and subtract the two numbers it separates; the result will be divisible by 7 whenever the original is. For even larger numbers, use the fact that 999,999 is divisible by seven (as the previous test will verify): add blocks of 6 digits together. Combining this with the previous test, you use an alternating sum of blocks of 3 digits. That is, 4,895,879,234,895,897,345,892 is divisible by 7 if 892 - 345 + 897 - 895 + 234 - 879 + 895 - 4 is.
Personally, I find it easier to do long division, which is effectively the same thing as subtracting numbers that are obvious multiples of 7 that are close in size. That requires having a good working knowledge of the multiplication/division table, so the above method using mainly addition and subtraction might be faster for some.
As a sort of highjack question (since the OP’s OP has been answered), why are divisibility tests for 7 so much more convoluted than all the others at least up to 13?
1: Easy, since given by definition.
2. Easy, since a component of base 10, which means repeatibility.
5. Easy, same as 2.
10. Easy, the actual base, otherwise same as 2 or 5.
But what of 4 and 8? I guess we could reconsider numbers in base 100 or 1,000 here, thus getting a repeatible pattern. And I guess that’s what actually is happening. Is this right?
3 and 9? It seems to be just a fluke, really, that the add-them-up method works. Is there something else? They’re both powers of 3, but I don’t know how that might matter.
11 is like 3 and 9, but alternating addition and subtraction. Is that a fluke, too? 11 is not a power of 3, so I got nothing here. (3 is one more than 2, and 11 is one more than 10, so that might be important. Is there an add-them-up method for 6, then?)
6 and 12 are combos (of 3 and 2 for 6 and 3 and 4 for 12), which makes sense for the same reason that a convoluted way to tell if a number is divisible by 10 is to check to see if it’s divisible by 5 and 2).
Then 13 is hard again. . . .
To determine whether a number with three-plus-digits is divisible by four, check the last two digits. If they are divisible by four, the entire number is.
To determine whether a number with 3-plus digits is divisible by four, check the last three digits. If the last two are divisible by 8, and the other is even, the entire number is a multiple of 8. If the last two are divisible by four but not by eight, and the other is odd, then the whole number is a multiple of eight.
Both these methods only require memorizing the twenty-five multiples of four from 0 to 96.
The adding-up method for 3 & 9 is called digit sums. (Well, Isaac Asimov called it that.) A shortcut in doing that, for divisibility by 3, is to discard all 3s, 6s, & 9s in the number you are testing. For 6 check for evenness (obviously trivial) and then use the digit-sum method for 3. For 9 use the digit sum method but discard all 9s.
In base n, there’s going to be a simple divisibility test for any k that divides either n or n - 1, and for k = ab where a divides n and b divides n - 1. Two and five divide ten, three and nine divide nine, four and eight are powers of two, and six is the product of two and three.
Also in base n there will always be an alternating digit sum test for n+1 since n is congruent to -1 mod n+1 and n^2 is congruent to 1 mod n+1. ( n^2 = (n+1)(n-1) + 1 )
I think that this is pretty much what I meant by thinking in terms of base 100. Divide the number up into groups of two, where each pair is considered a “digit.” Now that I think about it, the same trick you mention for 8 could work with 4, too. Basically, double the ten’s digit and add it to the one’s digit. If that’s divisible by 4, so is the whole thing. I think. So, for 8, that would be quadruple the hundred’s digit added to double the ten’s digit added to the one’s digit. Again, I think.
Ah. This is also why the 9’s and 3’s work out as they do, except without the alternating, isn’t it?
100a + 10b + c ≡ (11∙9 + 1)a + (9 + 1)b + c ≡ a + b + c (mod 9).
(This works with 3, too, since everything that is 0 (mod 9) must also be 0 (mod 3).) Also, I’m sure it’ll work with more than 3 digits.
Incidentally, why do you determine n[SUP]2[/SUP] by (n + 1)(n − 1) + 1? I would think that if n ≡ − 1, that n[SUP]2[/SUP] ≡ n∙n ≡ (− 1)(− 1) ≡ 1 (mod n + 1). Is there some nuance I’m missing?
Thus in octal there is a trivial test (sum of the digits) for divisibility by 7.
And in hexadecimal there is an easy test for divisibility by 3 and 5 (since 3 times 5 = 15), and an easy one for 17. However, 7, 11 and 13 are harder.
If you care, here is a test for divisibility by 7 (but I think it easier just to divide), but I was having trouble falling asleep last night, so here goes:
Take the units place, add three times the tens place, add twice the hundreds place, subtract the thousands place, subtract three times the ten thousands place, subtract twice the hundred thousands place. Continue using the using coefficients 1, 3, 2, -1, -3, -2. If the result is divisible by 7, so is the original number (and conversely). These numbers are the remainders when successive powers of 10 are divided by 7 (technically the absolutely least remainders, although you could also use the series 1, 3, 2, 6, 4, 5 if you don’t want to subtract).
Hari, the method you just posted is one of the methods from the link in post #2.
I guess I was avoiding using the theorem that (ab) mod m = ((a mod m)(b mod m)) mod m. However, I don’t really see a big difference between the two ways. It’s a fairly trivial fact that both methods explain in one line.
You could check the Trachtenberg texts, (I’m too lazy to search), there is a way of multiplying by 7, maybe some of you thinkers can deduce something smart.
Multiply the units digit by four and add the tens digit. If the result is divisible by 13, so is the number.
Not a very useful one, but it works.
Here’s the argument from a charming book Excursions in Number Theory by C. Stanley Ogilvy and John T. Anderson:
Without loss of generality, take a four-digit number abcd. We can rewrite this as :
1000a + 100b + 10c + d
= 999a + 99b + 9c
-
a + b + c + d
Now the first number after the equal sign is always divisible by 3 (or 9). Thus, for the entire number to be divisible by 3 (or 9), we need a + b + c + d to be divisible by 3 (or 9).
ETA: This uses the theorem that if a and b are both divisible by c, then a + b is divisible by c, which can be shown using the transitivity property of modulo arithmetic.
This is because 4 is the inverse of 10 modulo 13.
Suppose 4a + b = 13k
-> 10 (4a + b) = 130k
-> 40a + 10b = 130k
-> a + 10b = 130k - 39a
-> a + 10b = 13(10k - 3a)
In other words, any non-negative integer can be written uniquely as 10b + a where 0 <= a <= 9. And when 4a + b is a multiple of 13 so is 10b + a.
All the divisibility tests basically work on the same principle: to test for divisibility by d, or more generally for the remainder when you divide by d, is to work in arithmetic modulo d. But we write numbers in base 10, which is to say, as linear combinations of powers of 10. So the series of coefficients to use in interpreting a string of digits modulo d is the series of powers of 10 modulo d (that is, 1 mod d, 10 mod d, 10^2 mod d, …).
One of two things happens with this series: Either this series eventually hits 0 and stays there, or it eventually returns to 1 and starts cyclically repeating. [The latter happens if 10 is coprime to d; otherwise, the former]. The longer the series takes to do this, the less nice the corresponding divisibility rule.
In other words: the niceness of the divisibility rule for d corresponds to the size of the smallest multiple of d which is either a power of 10 or one less than a power of 10.
[On top of that, the one last bit of sophistication is that we can restrict attention to the case where d is a prime power (since divisibility by a product of powers of distinct primes is the same as divisibility by each factor).]
Everything I’ve said so far works no matter what 10 is, whether it’s “two”, “ten”, or “seventy-six”. But let’s look at what this implies for 10. For the various prime powers d, what does the series of powers of 10 modulo d look like? How long does it take before it hits 0 or re-hits 1? (Or -1, after which it will just take as long again to come back to 1). Well, here’s a chart of the powers of 10 modulo the first several d:
Mod 2: 1, 0
Mod 3: 1, 1
Mod 2^2: 1, 2, 0
Mod 5: 1, 0
Mod 7: 1, 3, 2, -1
Mod 3^2: 1, 1
Mod 11: 1, -1
Mod 13: 1, -3, -4, -1
Mod 17: 1, -7, -2, -3, 4, 6, -8, 5, -1
Mod 19: -9, 5, -7, 6, 3, -8, -4, -2, -1
So, yeah, 7 is a little bad, but not nearly as bad as 17 and 19. The reason the divisibility tests for these aren’t very nice is simply because it takes so long before a string of 9s is divisible by them (in math jargon, 10 has a high multiplicative order modulo these; in fact, 10 is actually a primitive root modulo each of these).
On the other hand, the divisibility test for 13, which is exactly as arduous as that for 7, might be considered surprisingly nice…
If you want surprisingly nice compute the sequence for 41 and compare it to those of 37 and 43.
I came in to mention this, but I wasn’t sure it was exhaustive.
IIRC this can be generalized to any base; e.g. if you were using base 12 the number would be divisible by 11 if the sum of the digits is divisible by 11.