Option Explicit
Private Sub Command1_Click()
Dim i As Long
For i = 3 To 100 Step 2 '判断3-100的数是否为素数,因双数肯定不是素数,故步长为2
If panduan(i) Then '如果当前i为素数
If panduan(i + 2) Then '判断比i大2的数是否为素数
Print i, i + 2 '输出孪生素数
End If
End If
Next i
End Sub
Public Function panduan(n As Long) As Boolean '判断n是否为素数
Dim i As Long
For i = 2 To n - 1
If n Mod i = 0 Then
panduan = False
Exit Function
End If
Next i
panduan = True
End Function