New user need help with perfect numbers.

Quote:

>Hi, how are you? I'm wanting to write a new method to return true or

>false depending on whether the receiver is a perfect number. A perfect

>number is one that is equal to all of its factors other than itself.

>(ie. 6 = 1 + 2 + 3). The only thing is, I have no idea where to start,

>let alone finish. Any comments or advice you may have would really be

>greatly appreciated. Thanks a lot.

I presume that you mean that it's equal to the SUM of all of its (prime)

factors, excluding itself.

I also assume that this is a homework assignment you hope someone will

do?? :-)

Let's list what you know:

* Perfect numbers are the sum of all prime factors

(excluding the number, but including 1.)

* Sums are easy, given the numbers to add.

* The numbers to add are the factors.

Thus, you need to find the factors and then add them up. Finding the

prime factors of an integer is an old problem, and one that either you've

had before or is readily available in a text book. There are simple (and

slow) solutions too. You probably don't need anything more than brute

force, and if you think about it a bit...

Dave

__________________________________

David N. Smith

IBM T J Watson Research Center

Hawthorne, NY

__________________________________

Any opinions or recommendations

herein are those of the author

and not of his employer.