18 lines
448 B
Text
18 lines
448 B
Text
Print "The first 4 perfect numbers are:"
|
|
For i = 2 To 10000
|
|
If isPerfect(i) <> 0 Then Print i; " ";
|
|
Next i
|
|
|
|
Function isPerfect (n)
|
|
If n < 2 Then isPerfect = 0
|
|
If n Mod 2 = 1 Then isPerfect = 0
|
|
sum = 1
|
|
For i = 2 To Sqr(n)
|
|
If n Mod i = 0 Then
|
|
sum = sum + i
|
|
q = n \ i
|
|
If q > i Then sum = sum + q
|
|
End If
|
|
Next
|
|
If n = sum Then isPerfect = -1 Else isPerfect = 0
|
|
End Function
|