17、有这样一个函数,对于任意整数n,都能返回写出0到n之间出现“1”的个数。例如,f(13)=6。请注意f(1)=1,那么下一个能实现f(n)=n的最大数字是什么?
以下为验证代码:
Option Explicit
Private Sub Command1_Click()
Dim i As Long
Dim s As Double
Dim s2 As Double
Dim s1 As Double
Dim s3 As Double
s = 0
s1 = 1
s2 = 1
s3 = 1
For i = 1 To 20
s = s + s2 * 2 + s3 * 10 + 1
Debug.Print i, s2, s
s2 = s3 * 10 + s2 * 10
s3 = s3 * 10
Next
End Sub
程序输出结果:
1 1 13
2 20 154
3 300 1755
4 4000 19756
5 50000 219757
6 600000 2419758
7 7000000 26419759
8 80000000 286419760
9 900000000 3086419761
10 10000000000 33086419762
11 110000000000 353086419763
12 1200000000000 3753086419764
13 13000000000000 39753086419765
14 140000000000000 419753086419766
15 1.5E+15 4.41975308641977E+15
16 1.6E+16 4.64197530864198E+16
17 1.7E+17 4.8641975308642E+17
18 1.8E+18 5.08641975308642E+18
19 1.9E+19 5.30864197530864E+19
20 2E+20 5.53086419753086E+20
可以看出那个数在1000000000-2222222221之间(10位数)
临时写这点发出来,免得以后偷懒不写了