|

楼主 |
发表于 2023-3-3 16:09
|
显示全部楼层
本帖最后由 ysr 于 2023-3-4 21:29 编辑
偶数的情况,得到10组解:
x=4 y=9 z=10
x=6 y=20 z=21
x=8 y=35 z=36
x=10 y=54 z=55
x=12 y=77 z=78
x=14 y=104 z=105
x=16 y=135 z=136
x=18 y=170 z=171
x=20 y=209 z=210
x=22 y=252 z=253
公式是:
x = 2 * n + 2
y = 2 * (n + 1) ^ 2 + n
z = 2 * (n + 1) ^ 2 + n + 1
代码如下:
Private Sub Command1_Click()
'代码为x是偶数的解,存一下吧
Dim p, q, x, y, z
A = Val(Text1)
n = 1
Do While Val(n) <= A
x = 2 * n + 2
y = 2 * (n + 1) ^ 2 + n
z = 2 * (n + 1) ^ 2 + n + 1
If y > 0 And z > 0 Then
s2 = s2 + 1
s1 = s1 & "x=" & x & " y=" & y & " z=" & z & vbCrLf
Else
s2 = s2
End If
n = n + 1
Loop
If Val(s2) > 0 Then
Text2 = s1
Else
Text2 = "wu jie"
End If
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
End Sub
Private Sub Command1_Click()
'代码为x是奇数的解,存一下吧
Dim p, q, x, y, z
A = Val(Text1)
n = 1
Do While Val(n) <= A
x = 2 * n + 1
y = 2 * n ^ 2 + 3 * n
z = 2 * n ^ 2 + 3 * n + 1
If y > 0 And z > 0 Then
s2 = s2 + 1
s1 = s1 & "x=" & x & " y=" & y & " z=" & z & vbCrLf
Else
s2 = s2
End If
n = n + 1
Loop
If Val(s2) > 0 Then
Text2 = s1
Else
Text2 = "wu jie"
End If
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
End Sub
|
|