|

楼主 |
发表于 2020-8-15 14:37
|
显示全部楼层
间距为10的孪生素数对是存在的且有无穷多组,下面是程序结果及代码:
3与223之间有5组4生素数对:
/17/19/29/31
/29/31/41/43
/59/61/71/73
/137/139/149/151
/179/181/191/193。
代码如下:(仅发主程序)
Private Sub Command1_Click()
Dim a, b
a = Val(Text1) * 2 + 1
a1 = a
q = 2 * Val(Text2) + 23
m = Sqr(q)
If Right(a, 1) Mod 2 = 0 Then
a = a + 1
Else
a = a
End If
s = 0
a2 = Val(Text1)
Do While a2 * 2 + 13 <= m
B1 = a2 * 2 + 9
b2 = a2 * 2 + 11
b3 = a2 * 2 + 21
b4 = a2 * 2 + 23
c1 = fenjieyinzi0(Val(B1))
C2 = fenjieyinzi0(Val(b2))
c3 = fenjieyinzi0(Val(b3))
D1 = fenjieyinzi0(Val(b4))
If InStr(c1, "*") = 0 And InStr(D1, "*") = 0 And InStr(C2, "*") = 0 And InStr(c3, "*") = 0 Then
s = s + 1
Print B1, b2, b3, b4
Text3 = Text3 & "/" & B1 & "/" & b2 & "/" & b3 & "/" & b4 & vbCrLf
Else
s = s
End If
a2 = a2 + 1
a = a2 * 2 + 1
Loop
a2 = a2
s1 = s
Do While a2 * 2 + 23 <= q
B1 = a2 * 2 + 9
b2 = a2 * 2 + 11
b3 = a2 * 2 + 21
b4 = a2 * 2 + 23
c1 = fenjieyinzi0(Val(B1))
C2 = fenjieyinzi0(Val(b2))
c3 = fenjieyinzi0(Val(b3))
D1 = fenjieyinzi0(Val(b4))
If InStr(c1, "*") = 0 And InStr(D1, "*") = 0 And InStr(C2, "*") = 0 And InStr(c3, "*") = 0 Then
s1 = s1 + 1
Print B1, b2, b3, b4
Text3 = Text3 & "/" & B1 & "/" & b2 & "/" & b3 & "/" & b4 & vbCrLf
Else
s1 = s1
End If
a2 = a2 + 1
Loop
Combo1 = a1 & "与" & q & "之间有" & s1 & "组4生素数对:" & vbCrLf & Text3
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Combo1 = ""
Form1.Cls
End Sub
|
|