|
楼主 |
发表于 2023-2-17 18:06
|
显示全部楼层
本帖最后由 ysr 于 2023-2-21 23:58 编辑
'代码如下,有vb6.0的话复制黏贴就可以运行的:
Private Function fenjieyinzi(sa As String) As String
Dim x, A, B
x = sa
B = Int(Sqr(Val(x)) / 2)
If x = 3 Or x = 2 Then
A = True
Else
If x Mod 2 = 0 Then
A = False
Else
For I = 3 To 2 * B + 1 Step 2
If x Mod I = 0 Then
A = False
Exit For
Else: A = True
End If
Next
End If
End If
If A = True Then
fenjieyinzi = "这是个素数"
Else
fenjieyinzi = "2*2"
End If
End Function
Private Sub Command1_Click()
Dim a, b
a = Val(Text1)
a3 = a
q = Val(Text2)
Do While a <= q
s = 0
m = Sqr(a)
a1 = 3
Do While a1 <= m
b = a - a1
c = fenjieyinzi(Val(a1))
d = fenjieyinzi(Val(b))
If InStr(c, "*") = 0 And InStr(d, "*") = 0 Then
s = s + 1
Else
s = s
End If
a1 = a1 + 2
Loop
a2 = a1
s1 = s
Do While a2 <= a / 2
B1 = a - a2
C1 = fenjieyinzi(Val(a2))
D1 = fenjieyinzi(Val(B1))
If InStr(C1, "*") = 0 And InStr(D1, "*") = 0 Then
s1 = s1 + 1
Else
s1 = s1
End If
a2 = a2 + 2
Loop
If s <= 8 Then
Text3 = Text3 & CStr(a) & " " & CStr(s) & " " & CStr(s1) & vbCrLf
Print a, s, s1
s2 = s2 & "/" & s
If s = 0 Then s5 = s5 & CStr(a) & " " & CStr(s) & " " & CStr(s1) & vbCrLf: s7 = s7 + 1
Else
s2 = s2
End If
a = a + 2
Loop
s3 = Mid(s2, 2)
s4 = min(Trim(s3))
s6 = "(偶数) (偶数方根内的素数和对个数,仅输出个数低于8的) (总素数和对个数)"
s8 = "含有0个小根拆的偶数有" & s7 & "个分别如下:"
Combo1.Text = "偶数" & a3 & "和" & q & "之间的偶数的方根内最少拆分个数为:" & s4 & ", 分别列表如下:" & vbCrLf & s6 & vbCrLf & Text3.Text
Text4 = s8 & vbCrLf & s5
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Combo1 = ""
Form1.Cls
End Sub
Private Function min(ByVal lists As String) As String
Dim temp As Long
Dim a() As String
a = Split(lists, "/")
Dim b As Long
temp = a(0)
For b = 0 To UBound(a)
If temp > a(b) Then temp = a(b)
Next
min = temp
End Function
|
|