|
|

楼主 |
发表于 2026-4-2 08:13
|
显示全部楼层
本帖最后由 ysr 于 2026-4-2 23:52 编辑
Private Function fenjieyinzi(sa As String) As String
Dim x, a, b, k As String
a = Val(sa)
x = 3
If a <= 1 Or a > Int(a) Then
If a = 1 Then
fenjieyinzi = "它既不是质数,也不是合数"
Else
MsgBox "error"
End If
Else
Do While a / 2 = Int(a / 2) And a >= 4
If b = 0 Then
fenjieyinzi = fenjieyinzi & "2"
b = 1
Else
fenjieyinzi = fenjieyinzi & "*2"
End If
a = a / 2
k = a
Loop
Do While a > 1
Do While x <= Sqr(a)
Do While a / x = Int(a / x) And a >= x * x
If b = 0 Then
fenjieyinzi = fenjieyinzi & x
b = 1
Else
fenjieyinzi = fenjieyinzi & "*" & x
End If
a = a / x
Loop
x = x + 2
Loop
k = a
a = 1
Loop
If b = 1 Then
fenjieyinzi = fenjieyinzi & "*" & k
Else
fenjieyinzi = "这是一个质数"
End If
End If
End Function
Private Sub Command1_Click()
Dim a, b
a = Val(Text1)
p1 = 3
Do While p1 <= a
p1 = p1: p2 = p1 + 210: p3 = p2 + 210
p4 = p3 + 210: p5 = p4 + 210: p6 = p5 + 210: p7 = p6 + 2310
p8 = p7 + 210: p9 = p8 + 210: p10 = p9 + 210
p11 = fenjieyinzi(Val(p1)): p12 = fenjieyinzi(Val(p2)): p13 = fenjieyinzi(Val(p3))
p14 = fenjieyinzi(Val(p4)): p15 = fenjieyinzi(Val(p5)): p16 = fenjieyinzi(Val(p6)): p17 = fenjieyinzi(Val(p7))
p18 = fenjieyinzi(Val(p8)): p19 = fenjieyinzi(Val(p9)): p20 = fenjieyinzi(Val(p10))
If InStr(p11, "*") = 0 And InStr(p12, "*") = 0 And InStr(p13, "*") = 0 And InStr(p14, "*") = 0 And InStr(p15, "*") = 0 And InStr(p16, "*") = 0 And InStr(p17, "*") = 0 And InStr(p18, "*") = 0 And InStr(p19, "*") = 0 And InStr(p20, "*") = 0 Then
s11 = s11 & "(" & p1 & " " & p2 & " " & p3 & " " & p4 & " " & p5 & " " & p6 & " " & p7 & " " & p8 & " " & p9 & " " & p10 & " ) " & vbCrLf
s12 = s12 + 1
End If
p1 = p1 + 2
Loop
If s12 >= 1 Then
Text2 = "在" & Text1 & "内的这样的素数组有" & s12 & " 组: " & vbCrLf & s11
Else
Text2 = "wu jie"
End If
Combo1 = Text2
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Combo1 = ""
Form21.Cls
End Sub
|
|