to accomplish a goal, there's alway a stupid way and a much clever way, here's the stupid way:
as stated in the question, a perfect number is the sum of its factors including 1. you want fo find all perfect numbers between 1 and 1000.
1. firstly, you know this has to be done in a loop from 1 to 1000.
2. for each number between 1 to 1000, find its factors and compare the sum with the value
(hint: to find one's factors, devide the number by all nubers smaller than it, factors are ones with MOD = 0, if you dont know what MOD is, google it
e.g. 10:
10/1 MOD 0 (Factor),
10/2 MOD 0 (Factor),
10/3 MOD 1 (nop),
10/4 MOD 2 (nop) ,
10/5 MOD 0 (Factor) ,
10/6 MOD 4 (nop) ,
10/7 MOD 3 (nop) ,
10/8 MOD 2 (nop) ,
10/9 MOD 1 (nop)
therefore factors of 10 are 1, 2, 5, the sum is 8 which does not equal to 10, so 10 is not a perfect number.
makes sense?
[ 本帖最後由 fsnow 於 2007-10-24 23:00 編輯 ]