0

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?

24n8
  • 1,455

2 Answers2

5

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?

How many times does each allowed digit appear in the units place?
How many times does each allowed digit appear in the tens place?

Calvin Lin
  • 68,864
  • may I get some hints for *(10+1)? I cannot think of +1 for. Thanks! – helloworld Nov 09 '22 at 03:51
  • @JacquelineP. When a digit appears in the one's place, show that the contribution to the sum is "digit81". When a digit appears in the ten's place, show that the contribution to the sum is "digit810". Hence, the contribution of the digit to the sum is "digit8(1+10)". – Calvin Lin Dec 30 '22 at 19:15
0

I don't know if you will find it better, but the sum of all the numbers with $7$s is $7 \cdot 10 + 450$ from the ones with a $7$ in the ones place and $7 \cdot 100+45$ from the ones with $7$ in the tens place less $77$ for the one we counted twice. That makes $70+450+700+45-77=1188$ Similarly the ones with $8$s are $80+450+800+45-88=1188+10+100-11=1287$. We have counted $78$ and $87$ twice, so the total deduction is $1188+1287-165=2475-165=2310$. The fnal sum is then $5050-2310=2740$

Ross Millikan
  • 374,822