5/22/2025 at 6:52:38 AM
This is more of a "dirty high school algebra" trick, but factoring polynomials by hand at that level got a lot easier once I realized every composite number below 100 has to be divisible by 2, 3, 5, or 7. If none of those divide it, then it's prime and you can stop factoring right there.It similarly turns out the only "non-obvious" composite under this rule is 7*13=91, all the rest can be pretty quickly tested using the normal rules. 49 is 7², so it's similarly easy to recognize. All the others are an easy primality test.
A few randomly generated numbers to show this off:
* 31? Not divisible by 2, 3, or 5 - below 7² so no risk of 7 division either. Prime. 31=31¹.
* 69? Divisible by 3. 69 = 3*23. 23? Not divisible by 2, 3, 5 - so you can stop factoring there. 69=3¹23¹.
* 92? Divisible by 2, to 2*46 - again, divisible by 2, to 2²23 - 23 isn't divisible by 2, 3 or 5, so 92 = 2²23¹.
* 68 = 2¹34 = 2²17, and 17 is not divisible by 2, 3 or 5, so you can stop there. 2²17¹.
High school textbooks generally don't use numbers higher than 100 to preclude students who don't have calculators, so this trick came in handy many times for me. It also happens to gesture at the notion that primes are surprisingly common at low numbers, and then thin out rapidly as you climb higher and higher.
by hiAndrewQuinn
5/22/2025 at 1:25:57 PM
I assume you also know the trick of adding the columns to test divisibility by three: 387 becomes 3+8+7, which is 18, which becomes 1+8 = 9. This works because 10 % 3 = 1, so 100 = 99+1 (etc.), with the effect that each column can be counted as if it was units.To apply the same trick to a multiple of 7, the tens column is worth 3 (10 % 7 = 3), so 91 -> 27 + 1 -> 6 + 8 -> 3 + 4 -> 7. The value is different in the next column (100 % 7 = 2). This trick is no help at all but I still like it.
(Finished editing out mistakes now.)
by card_zero
5/23/2025 at 4:47:29 AM
Hm...14 => 1 (3^1) + 4 (3^0) => 7 => divisible by 7.
21 => 6 (3^1) + 1 (3^0) => 7 => also divisible by 7.
7 * 53 = 371 => 3 (3^2) + 7 (3^1) + 1 (3^0) => 27 + 21 + 1 => 49 => ALSO divisible by 7!
My word! This is the intuition I always suspected was possible after studying how bases worked, but I never took the time to investigate on my own.
by hiAndrewQuinn
5/23/2025 at 12:05:22 PM
Hmm, no. There's a hazard of false positives here (which is why I had mistakes to fix previously). It's not all about the number 3; you don't want to multiply columns by 3², 3¹, 3⁰. Instead you want the remainder of the division of (ten to the column number) by seven (or whatever divisor you're checking).That's a repeating pattern. In the case of 3 the pattern has length 1, and it goes (1, 1, 1, ...). In the case of 7 the pattern has length 6, and it goes (1, 3, 2, 6, 4, 5), starting at the units column. If that looks a bit pseudorandom, there's a good reason, it's vaguely similar to an old-fashioned PRNG.
(The pattern starts again with 1 in the millions column, because 142857 * 7 = 999999. Hence 2 million divided by 7 has remainder 2, 3 million divided by 7 has remainder 3, and so on.)
So 371 should be understood as 3*2 + 7*3 + 1*1, which is 28.
Or as another example, 6993 => 6*6 + 9*2 + 9*3 + 3*1, which is 84.
by card_zero
5/23/2025 at 3:50:23 PM
Waaait a minute though. The results for (10 to the n) % 7 and the results for (3 to the n) % 7 are the same, so your version works precisely. That's because the difference is 7.by card_zero