> 其他 >
用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
求修正
人气:303 ℃ 时间:2020-01-29 00:48:19
解答
思路与方法:
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这个思路我也知道,但具体到证明i与n-i为素数时就搞不清了

我做了一个,你自己看吧!

推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版