不好意思,能在今天晚上12点之前给我解答一下吗.用vb验证一个大于5的奇数等于3个素数之和,
不好意思,能在今天晚上12点之前给我解答一下吗.用vb验证一个大于5的奇数等于3个素数之和,
输出格式为55=3+5+47
77=2+2+73
奖金什么的还可以再加的
Function CombinePrime(Num)
Dim a As Long,b As Long,c As Long
a = 1
Do While a = 2
b = b + 1
c = Num - a - b
If IsPrimeNum(a) And IsPrimeNum(b) And IsPrimeNum(c) Then
MsgBox Str(Num) & "由素数" & Str(a) & Str(b) & Str(c) & "组成"
Exit Function
End If
Loop
Loop
End Function
Function IsPrimeNum(Num) As Boolean
Dim i As Long,j As Long
j = Int(Sqr(Num))
If Num >= 2 Then IsPrimeNum = True
For i = 2 To j
If Num Mod i = 0 Then
IsPrimeNum = False
Exit For
End If
Next
End Function
Private Sub Command1_Click()
Dim a As Integer
If Text1.Text "" Then
a = Text1.Text
If a Mod 2 0 And a >= 7 Then
Call CombinePrime(a)
Else
MsgBox "输入错误,请输入大于5的奇数!"
End If
Else
MsgBox "输入错误,请输入大于5的奇数!"
End If
End Sub