用VB编程序验证哥德巴赫猜想,即一个大于等于6的偶数可以表示为两个素数之和尽量别用太复杂高端的语句,我们很多都没学过Private Sub Form_Click()Dim a As Long,b As Long,c As Long,i As Long,t As Longc = a - b
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 16:16:56
用VB编程序验证哥德巴赫猜想,即一个大于等于6的偶数可以表示为两个素数之和尽量别用太复杂高端的语句,我们很多都没学过Private Sub Form_Click()Dim a As Long,b As Long,c As Long,i As Long,t As Longc = a - b
用VB编程序验证哥德巴赫猜想,即一个大于等于6的偶数可以表示为两个素数之和
尽量别用太复杂高端的语句,我们很多都没学过
Private Sub Form_Click()
Dim a As Long,b As Long,c As Long,i As Long,t As Long
c = a - b
Do
a = Val(InputBox("输入不小于6的偶数"))
Loop Until a >= 6 And a Mod 2 = 0
If (b = 2 Or b = 3) And (c = 2 Or c = 3) Then
Print a + "=" + b + "+" + c
Else
For i = 2 To Sqr(b)
If b Mod i = 0 Then
For t = 2 To Sqr(c)
If c Mod t = 0 Then Print a + "=" + b + "+" + c
Next t
Next i
If i > Sqr(b) Then
If t > Sqr(c) Then Print a + "=" + b + "+" + c
End If
End If
End Sub
求修正
用VB编程序验证哥德巴赫猜想,即一个大于等于6的偶数可以表示为两个素数之和尽量别用太复杂高端的语句,我们很多都没学过Private Sub Form_Click()Dim a As Long,b As Long,c As Long,i As Long,t As Longc = a - b
思路与方法:
1,输入一个大于等于6的偶数n.
2,采用循环:
For i = 2 to n-2
if i 是素数 And n-i 是素数 Then
输出:i,n-i
Exit For
End If
Next i