← Complete problem index

PROJECT EULER · #0156

Counting Digits

Statement only · SolvedOriginal problem ↗

Starting from zero the natural numbers are written down in base 10 like this:
0123456789101112

Consider the digit d=1. After we write down each number n, we will update the number of ones that have occurred and call this number f(n,1). The first values for f(n,1), then, are as follows:

nf(n,1)00112131415161718191102114125

Note that f(n,1) never equals 3.
So the first two solutions of the equation f(n,1)=n are n=0 and n=1. The next solution is n=199981.

In the same manner the function f(n,d) gives the total number of digits d that have been written down after the number n has been written.
In fact, for every digit d0, 0 is the first solution of the equation f(n,d)=n.

Let s(d) be the sum of all the solutions for which f(n,d)=n.
You are given that s(1)=22786974071.

Find s(d) for 1d9.

Note: if, for some n, f(n,d)=n for more than one value of d this value of n is counted again for every value of d for which f(n,d)=n.

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.