Private Sub Command1_Click()
Dim a As Long
Dim i As Long
Dim s As Boolean
s = True
a = InputBox("请输入一个自然数", "输入")
'--------以下为判断自然数
If Not IsNumeric(a) Then Exit Sub '判断输入的是否是数字
If Fix(a) <> a Then Exit Sub '判断是否为整数
If a < 0 Then Exit Sub '判断是否小于0
'--------以上为判断自然数
Do While s
i = i + 1
If Fix(Sqr(i + a)) = Sqr(i + a) Then
If i - a > 0 Then
If Fix(Sqr(Abs(i - a))) = Sqr(Abs(i - a)) Then s = False
End If
End If
Loop
Print i
End Sub