Divisibility by 7
From ProofWiki
Theorem
An integer $X$ with $n$ digits ($X_0$ in the ones place, $X_1$ in the tens place, and so on) is divisible by $7$ if and only if $\displaystyle \sum_{i=0}^{n-1} (3^i X_i)$ is divisible by $7$.
Direct Proof
| \(\displaystyle \) | \(\displaystyle X\) | \(=\) | \(\displaystyle 10^0 X_0 + 10^1 X_1 + \cdots + 10^{n-1} X_{n-1}\) | \(\displaystyle \) | |||
| \(\displaystyle \) | \(\displaystyle \) | \(=\) | \(\displaystyle \sum_{i=0}^{n-1} 10^i X_i\) | \(\displaystyle \) | |||
| \(\displaystyle \) | \(\displaystyle \) | \(=\) | \(\displaystyle \sum_{i=0}^{n-1} (10^i - 3^i + 3^i) X_i\) | \(\displaystyle \) | |||
| \(\displaystyle \) | \(\displaystyle \) | \(=\) | \(\displaystyle \sum_{i=0}^{n-1} ((10^i - 3^i) X_i) + \sum_{i=0}^{n-1} (3^i X_i)\) | \(\displaystyle \) |
The first addend is always divisible by $7$ because $10^i - 3^i$ always produces a number divisible by $7$ from the difference of two powers. So $X$ will be divisible by $7$ if and only if the second addend is divisible by $7$.
$\blacksquare$