Click to See Complete Forum and Search --> : I need help with an algotrithm
acp26b
February 19th, 2004, 08:40 AM
Trying to figure out the algotrithm that will find all perfect numbers between 1 and any given int.
A perfect number is defined as: A perfect number is an integer that is equal to the sum of it's divisors as an example 6 is divisible by 1,2 and 3 and 6=1+2+3.
Any help or ideas would be great, thanks.
jdenny
February 19th, 2004, 01:27 PM
Why don't you tell us what you've got so far (a skeleton is fine), and let us help you by filling up the missing parts?
Peace always,
<jdenny>
acp26b
February 19th, 2004, 08:19 PM
Here is what i know:
Find how many factors of n - this is where i am confused, i am not exactly sure how to find all the factors, if it matters i am using java to do it....the main reason is i dont know how big to make the array for the factors...
Check to see if the f1 + f2 ... = n
jdenny
February 20th, 2004, 07:40 AM
That's a good start!
For a recent discussion of how to find all the factors of a given integer, follow this thread:
http://www.antionline.com/showthread.php?s=&threadid=253049
Then instead of displaying the factors, store them in an array, and check to see if the sum is equal to the integer.
Peace always,
<jdenny>