I want to quickly sum values from 1 to 100, but exclude values with digits of 7 and/or 8 (e.g., 7,8,17,18,70,78,....) from the sum.
This is a mental math problem that I want to do in a really quick way. The fastest approach I could come up with is note that sum of 1 to 100 is $100*101/2=5050$. Then subtract sum of 70 to 79, which is $10 * 70 + 9 * 10 / 2 = 745$. Then subtract sum of 80 to 89 which is $745 + 100 = 845$. Then we need to subtract $7 + 8 + 17 + 18 + 27 + 28 + \ldots + 67 + 68 + 97 + 98 = 6 * 7 / 2 * 10 * 2 + 180 + 8 * (7 * 8) = 720$.
Let me explain the last expression. The $6 * 7 / 2 * 10 * 2 + 180$ is the sum of just the tens and the $8 * (7 * 8)$ is the sum of the ones. The $6*7/2 * 10$ is the sum of $10 + \ldots + 60$. We multiply this by 2 because there're two of these sums. 180 is sum of the tens part of 97 and 98. Then finally $8 * (7 * 8)$ is saying that there are eight 7s and 8s in the ones spot.
Can you come up with something better?
Here's a much faster way.
Hint: Ignore 100 first.
Claim: The sum of all the other numbers is
$$(1+2+3+4+5+6+9+0) \times 8 \times (10 + 1) = 30 \times 8 \times 11 = 2640.$$
Hence, the total is $2640 + 100 = 2740$.
Why is the claim true?