#P8680. Sum of Interesting Numbers
Sum of Interesting Numbers
Sum of Interesting Numbers
You are given an integer n. A number in the range [1, n] is called interesting if its decimal representation (without any leading zeros) contains at least one digit from the set \(\{2,0,1,9\}\). For example, when n = 40, the interesting numbers are: 1, 2, 9, all numbers between 10 and 32, as well as 39 and 40. Their sum is \(574\).
Your task is to compute the sum \(S\) of all interesting numbers in the range \(1 \le x \le n\). In other words, \[ S = \sum_{x=1}^{n} x \cdot \mathbf{1}\{\text{$x$ has at least one digit in }\{2,0,1,9\}\}, \] where \(\mathbf{1}\{\cdot\}\) is the indicator function.
inputFormat
The input consists of a single integer n (n \(\ge 1\)).
outputFormat
Output a single integer, which is the sum of all interesting numbers in the range \([1, n]\).
sample
40
574