A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself. We do some coding to find the Second Perfect Number

Code
============
Sub Perfect()

For n = 2 To 497
DoEvents
Cells(1, 1).CurrentRegion.Offset(1, 0).Clear

p = 0
For i = 1 To n
Cells(i + 1, 1) = i
Cells(i + 1, 2) = n / i

‘is used to make sure it is divisible as a whole number

Cells(i + 1, 3) = Int(n / i)

If i __ n And n / i = Int(n / i) Then
p = p + i
End If

Next
If n = p Then
MsgBox “You found a Perfect Number ” & p, vbOKOnly, “You are a rockstar!!”
End If

Next

End Sub

Chris Terrell

View all posts