I was recently looking up solutions to taking the modulus of a very large number ($\sim22$ digits). Because computers can't handle this operation on such large numbers I went looking and found a novel solution to taking a number's modulus in general:
Say you want to calculate $12345 \bmod 7$ (which equals $4$). You could go digit by digit and do the following:
- $1 \bmod 7 = 1$.
- Take the prior result ($1$) and put it in front of the next digit ($2$). This gives you $12$: $12 \bmod 7 = 5$.
- Take the prior result ($5$) and put it in front of the next digit ($3$). This gives you $53$: $53 \bmod 7 = 4$.
- Take the prior result ($4$) and put it in front of the next digit ($4$). This gives you $44$: $44 \bmod 7 = 2$.
- Take the prior result ($2$) and put it in front of the next digit ($5$). This gives you $25$: $25 \bmod 7 = 4$.
And voilà - the answer is $4$, however I couldn't exactly understand how to prove why. Any insights are greatly appreciated!