欧拉计划 发表于 2016-9-13 14:51:11

题目156:统计数字个数

本帖最后由 永恒的蓝色梦想 于 2020-7-31 10:36 编辑

Counting Digits

Starting from zero the natural numbers are written down in base 10 like this:
0 1 2 3 4 5 6 7 8 9 10 11 12....

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:

n f(n,1)
0      0
1      1
2      1
3      1
4      1
5      1
6      1
7      1
8      1
9      1
10      2
11      4
12      5
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 d ≠ 0, 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 1 ≤ d ≤ 9.

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.

题目:

从 0 开始的 10 进制数如下:
0123456789101112 ....

考虑 d=1,我们每写下一个数字,就更新数字1出现的次数,并且把这个数字叫做 f(n,1)。f(n,1) 的一些值如下:

n f(n,1)
0      0
1      1
2      1
3      1
4      1
5      1
6      1
7      1
8      1
9      1
10      2
11      4
12      5

注意,f(n,1) 永远不等于 3。

所以,f(n,1)=n 的前两个解为 n=0 和 n=1,下一个解就是 n=199981.

f(n,d) 以同样的方式,定义为从 1 写到 n 时,数字 d 的出现次数。

实际上,对于方程 f(n,d)=n,只要 d 不等于 0,0 就是方程的第一个解。

定义 s(d) 为 f(n,d)=n 所有解的和。

已知,s(1)=22786974071

对于 1 ≤ d ≤ 9,求 ∑ s(d)

注意:如果对于一些 n 来说,它能对不同的 d 都满足方程 f(n,d)=n,那么它每次满足方程时,都要进行统计。

guosl 发表于 2022-4-21 21:20:42

这个题目看来只有死做了。耗时比较厉害。
答案:
s(1):22786974071
s(2):73737982962
s(3):372647999625
s(4):741999999540
s(5):100000000000
s(6):2434703999430
s(7):1876917059570
s(8):15312327487352
s(9):360000000000
Sum=21295121502550
页: [1]
查看完整版本: 题目156:统计数字个数