The integer \(107\) contains the digit \(7\). The integer \(358\) does not contain the digit \(7\).
Determine the sum of all integers from \(1\) to \(2024\) that do not contain the digit \(7\).
Solution 1
In this solution, we will use the fact that the sum of the integers from \(1\) to \(n\), where \(n\) is some positive integer, is \(\frac{n(n+1)}{2}\). Consider the integers from \(1\) to \(100\). The sum of these integers is \(\frac{(100)(101)}{2} = 5050\).
The integers from \(1\) to \(100\) which do contain the digit \(7\) are \(7\), \(17\), \(27\), \(37\), \(47\), \(57\), \(67\), \(70\), \(71\), \(72\), \(73\), \(74\), \(75\), \(76\), \(77\), \(78\), \(79\), \(87\), \(97\). The sum of these \(19\) integers is \(1188\). Therefore, the sum of the \(100-19 = 81\) integers from \(1\) to \(100\) which do not contain the digit \(7\) is \(5050 - 1188 = 3862\).
There are \(81\) integers from \(101\) to \(200\) which do not contain the digit \(7\) as well. Each of these is \(100\) more than a corresponding integer between \(1\) and \(100\) which does not contain the digit \(7\). Thus, the sum of these \(81\) integers is \(3862 + 81(100)\).
We can use this approach to determine the sum of the integers which do not contain the digit \(7\) in various ranges of \(100\). This is summarized in the table below.
| Range of integers | Number of integers in range that do not contain a \(7\) | Sum of integers in range that do not contain a \(7\) |
|---|---|---|
| \(1\) to \(100\) | \(81\) | \(3862\) |
| \(101\) to \(200\) | \(81\) | \(3862 + 81(100)\) |
| \(201\) to \(300\) | \(81\) | \(3862 + 81(200)\) |
| \(301\) to \(400\) | \(81\) | \(3862 + 81(300)\) |
| \(401\) to \(500\) | \(81\) | \(3862 + 81(400)\) |
| \(501\) to \(600\) | \(81\) | \(3862 + 81(500)\) |
| \(601\) to \(700\) | \(81\) | \(3862 + 81(600)-700\) |
| \(701\) to \(800\) | \(1\) | \(800\) |
| \(801\) to \(900\) | \(81\) | \(3862 + 81(800)\) |
| \(901\) to \(1000\) | \(81\) | \(3862 + 81(900)\) |
| \(1001\) to \(1100\) | \(81\) | \(3862 + 81(1000)\) |
| \(1101\) to \(1200\) | \(81\) | \(3862 + 81(1100)\) |
| \(1201\) to \(1300\) | \(81\) | \(3862 + 81(1200)\) |
| \(1301\) to \(1400\) | \(81\) | \(3862 + 81(1300)\) |
| \(1401\) to \(1500\) | \(81\) | \(3862 + 81(1400)\) |
| \(1501\) to \(1600\) | \(81\) | \(3862 + 81(1500)\) |
| \(1601\) to \(1700\) | \(81\) | \(3862 + 81(1600)-1700\) |
| \(1701\) to \(1800\) | \(1\) | \(1800\) |
| \(1801\) to \(1900\) | \(81\) | \(3862 + 81(1800)\) |
| \(1901\) to \(2000\) | \(81\) | \(3862 + 81(1900)\) |
For the integers from \(2001\) to \(2024\), the only integers that contain the digit \(7\) are \(2007\) and \(2017\). Thus, the sum of the integers from \(2001\) to \(2024\) that do not contain a \(7\) is \[24 \times 2000 + \frac{(24)(25)}{2} - 2007 - 2017= 44\,276\]
Therefore, the overall sum of the integers from \(1\) to \(2024\) that do not contain the digit \(7\) is \[18(3862) +81(16\,600)-700 + 800 - 1700 + 1800 + 44\,276 = 1\,458\,592\]
Solution 2
Consider first the integers from \(000\) to \(999\) that do not contain the digit \(7\). (We can include \(000\) in this list as it will not affect
the sum.)
Since each of the three digits has \(9\) possible values (\(0\), \(1\), \(2\), \(3\), \(4\), \(5\), \(6\), \(8\), or \(9\)), there are \(9\times 9\times 9 = 729\) such
integers.
If we fix any specific digit in any of the three positions, there will
be exactly \(9\times 9 =81\) integers
with that digit in that position, as there are \(9\) possibilities for each of the remaining
digits. (For example, there are \(81\)
such integers ending in \(0\), \(81\) ending in \(1\), etc.)
We sum these integers by first summing the units digit column, then
summing the tens digit column, and then summing the hundreds digit
column.
Since each of the \(9\) possible units
digits occurs \(81\) times, the sum of
the units digit column of all integers from \(1\) to \(2024\) that do not contain a \(7\) is \[81(0) +
81(1) + 81(2) + 81(3) + 81(4) + 81(5) + 81(6) + 81(8) + 81(9) =
81(38)\]
Since each of the \(9\) possible tens digits occurs \(81\) times, the sum of the tens digit column of all integers from \(1\) to \(2024\) that do not contain a \(7\) is \[81(0 + 10 + 20 + 30 + 40 + 50 + 60 + 80 + 90) = 81(380)\] Similarly, the sum of the hundreds digits column is \[81(3800)\]
Thus, the sum of the integers from \(0\) to \(999\) that do not contain the digit \(7\) is \[81(38) + 81(380) + 81(3800) = 81(38)(1 + 10 + 100) = 81(38)(111) = 341\,658\] Each of the \(729\) integers from \(1000\) to \(1999\) which do not contain \(7\) is \(1000\) more than such an integer between \(0\) and \(999\). There are again \(729\) of these integers, as the first digit is fixed at \(1\), and each of the remaining three digits has \(9\) possible values. Thus, the sum of these integers from \(1000\) to \(1999\) is equal to the sum of the corresponding ones from \(0\) to \(999\) plus \(729(1000)\), or \[341\,658 + 729\,000= 1\,070\,658\]
For \(2000\) to \(2024\), the only integers that contain the digit \(7\) are \(2007\) and \(2017\). Thus, the sum of the integers from \(2000\) to \(2024\) that do not contain the digit \(7\) is \[25 \times 2000 + \frac{(24)(25)}{2} - 2007 - 2017= 46\,276\]
Therefore, the sum of the integers from \(1\) to \(2024\) that do not contain the digit \(7\) is \[341\,658 + 1\,070\,658 + 46\,276 = 1\,458\,592\]