|
发表于 2020-1-25 18:00:01
|
显示全部楼层
//试编程验证陈氏定理,即输入(>=6)任意大的偶数,用试凑法验证其能够分解成一个质数与两个质数乘积的和,如无解,提示陈氏定理不在在,程序结束。
Private Sub Command1_Click()
Dim n, n1, n2, i, j
n = Val(Text1)
For i = 2 To n
If zs(i) Then
For j = 2 To (n - i) / 2
If (n - i) Mod j = 0 Then
If zs(j) And zs((n - i) / j) Then
MsgBox n & "=" & i & "+" & j & "*" & (n - i) / j
Exit Sub
End If
End If
Next
End If
Next
MsgBox "不存在"
End Sub
Function zs(s) As Boolean
Dim i
For i = 2 To Sqr(s)
If s Mod i = 0 Then zs = False: Exit Function
Next
zs = True
End Function
|
|