在前1000个积自然数中, 计算恰好有3位为1的2进制数的个数?

来源:百度知道 编辑:UC知道 时间:2024/05/15 12:23:12
帮我哦
比如说111 1011 100011 等等用VB来求

111 貌似就一个?

在前1000个积自然数中, 计算恰好有3位为1的2进制数的个数?
Private Sub Command1_Click()
Dim i As Integer, j As Integer, m As Integer, n As Integer, c As Integer, w As Integer
c = 0
w = 0
For i = 1 To 1000
j = 2 * i - 1
Do While m = j \ 2
n = j Mod 2
If n = 1 Then w = w + 1
End If
j = j \ 2
Loop
If w = 3 Then c = c + 1
End If
Next i
Text1.Text = Str(c)
End Sub