主题:验证哥德巴赫猜想
Private Sub Command1_Click()
Dim x As Long, y As Long, k As Integer
k = 0
For x = 6 To 100 Step 2
For y = 2 To x - 2
If Prime(y) And Prime(x - y) Then
List1.AddItem x & "=" & y & "+" & x - y
k = k + 1
Exit For
End If
Next
Next
If y > x - 2 Then Text2.Text = ""
Label1.Caption = "6和10之间有" & k & "对素数和"
End Sub
Function Prime(n As Long) As Boolean
Dim i As Long
For i = 2 To n - 1
If n Mod i = 0 Then Exit For
Next
Prime = i = n
End Function
本想输出6-100之间所有的符合条件的素数和,但运行的结果只是其中的48对,没有将全部都输出。请大虾指点!!
[fly]多谢大虾光临指导[/fly]
Dim x As Long, y As Long, k As Integer
k = 0
For x = 6 To 100 Step 2
For y = 2 To x - 2
If Prime(y) And Prime(x - y) Then
List1.AddItem x & "=" & y & "+" & x - y
k = k + 1
Exit For
End If
Next
Next
If y > x - 2 Then Text2.Text = ""
Label1.Caption = "6和10之间有" & k & "对素数和"
End Sub
Function Prime(n As Long) As Boolean
Dim i As Long
For i = 2 To n - 1
If n Mod i = 0 Then Exit For
Next
Prime = i = n
End Function
本想输出6-100之间所有的符合条件的素数和,但运行的结果只是其中的48对,没有将全部都输出。请大虾指点!!
[fly]多谢大虾光临指导[/fly]