更新时间2018-03-06 19:58:03
Private Sub Command1_Click()
Dim i As Integer, n As Integer, flag As Boolean
Dim m As Integer
m = 0
For i = 1001 To 9999 Step 2
n = i
f = True
Do While n > 0
If prime(n) Then
n = n 10
Else
f = False
Exit Do
End If
Next i
Label1.Caption = "共有" & Str(m) & "个超级素数"
End Sub
Public Function prime(p As Integer) As Boolean
Dim k As Integer
If p = 1 Then
prime = False
Exit Function
Else
For k = 2 To Int(Sqr(p))
If p Mod k = 0 Then
prime = False
Exit Function
End If
Next k
End If
prime = True
End Function
Do 缺少 Loop
For i = 1 To 9999 Step 2
n = i
f = True
Do While n > 0
If prime(n) Then
m = m + 1
n = n 10
Else
f = False
Exit Do
End If
Loop
Next i