我们以N = 13000,K = 12031为例。当1到9中的每个数字被指定为最左边时,得到如下结果:
total
1 single digit number 9 * 1 9
10 two-digit numbers 9 * 10 99
100 three-digit numbers 9 * 100 999
1000 four-digit numbers 9 * 1000 9999
10000 five-digit numbers ---> here we have to start examining
Total
----
1 gets 13000 - 8 * (1 + 10 + 100 + 1000) = 4112 of them
2 gets 1111 5223
3 gets 1111 6334
4 gets 1111 7445
5 gets 1111 8556
6 gets 1111 9667
7 gets 1111 10778
8 gets 1111 11889
9 gets 1111 ----> answer is somewhere here
答案是: 9xxx
。现在看第二个数字。对于每个以一个或多个0结尾的数字,我们必须计算所有具有相同前缀的较低数字。
3 numbers with zero or nothing before 9000 11892
9 90 900
100 + 9 numbers with 90xx
9000 9001 9002.., but also 901 902.. 12001
答案是:91xx
,第三位数字。
2 numbers with zero or nothing before 9100
91 910 12003
10 four-digit numbers with 0 as third digit
9100 9101 9102.. 12013
1 number with zero or nothing before 9110
911 12014
10 numbers with 1 as third digit
9110 9111 9112.. 12024
1 number with zero or nothing before 9120
912 12025
+ 6
答案: 9126