|
Public Sub Test()
Dim a As Integer, b As Integer, c As Integer, d As Integer, i As Integer
For a = 1 To 40: For b = a To 40: For c = b To 40: For d = c To 40
If a + b + c + d = 40 Then
For i = 1 To 39
If CheckNum(i, a, b, c, d) = False Then Exit For
Next
If i = 40 Then Debug.Print a & "," & b & "," & c & "," & d
End If
Next: Next: Next: Next
End SubPublic Function CheckNum(Num As Integer, w As Integer, x As Integer, y As Integer, z As Integer) As Boolean
For a = -1 To 1: For b = -1 To 1: For c = -1 To 1: For d = -1 To 1
If a * w + b * x + c * y + d * z = Num Then
CheckNum = True
Exit Function
End If
Next: Next: Next: Next
End Function
答案是:1,3,9,27(跟我用心算的结果一样,并且是唯一解 :)
|
|