Elektrine lite

← Feed

@simontatham@hachyderm.io

Post #1098422

2026-03-31 10:20 UTC

@Taneb@hacksrus.xyz the idea is to use modular arithmetic: pick a small n, find the sum of all 10 digits mod n, and calculate the residue of 2^29 mod n by reducing the intermediate values as you go rather than reducing once at the end. The normal choice is to work mod 9. The sum of all ten digits is 0, because they come in pairs summing to 9. And 2^3 = 8 ≡ −1, so 2^6 ≡ 1, so 2^(any multiple of 6) ≡ 1 as well. Then 2^29 = 2^24 × 2^3 × 2^2 ≡ 1 × −1 × 4 = −4. If the number had all ten digits once each then its residue mod 9 would be 0, but in fact it's −4, so 4 must be missing. (With a bit more theory you can go straight to 2^6 ≡ 1 (mod 9) via the Fermat-Euler theorem, but I think this question is set before getting to that part of the course.) I've never thought of it before, but you could surely work mod 11 almost as easily, which eliminates the risk that the missing digit is one of the two that you can't tell apart mod 9!

Replies (1)

  • @simontatham@hachyderm.io 2026-03-31 10:34

    @Taneb@hacksrus.xyz … ok, that was badly explained. The _point_ of working mod 9 is that, mod 9, a number is congruent to the sum of its decimal digits (because any power of 10 is congruent to 1), so that normalises out the order that the digits occur in. If you work mod 11 then a number is congruent to the _alternating_ sum of its digits, because 10 is congruent to −1 rather than +1. So it's _not_ as easy like that. It should have been a red flag when I wrote "I've never thought of this before, but …". Sometimes the reason you've never thought of a thing before is that it's nonsense!

    Open ##1098420