Pages

Saturday, June 21, 2008

Programming Mathematica: Finding Perfect Numbers

Find all numbers less than or equal to 10000 which are equal to the sum of their proper positive divisors. These are the so called Perfect Numbers. For example 6 has proper positive divisors 1,2 and 3 ( 1+2+3=6 ).

Finding a solution to this problem can be done with the following Mathematica program.

PerfectQ [n_]:=Apply[Plus,Divisors[n]]== 2n
PerfectSearch[n_]:=Select[Range [n],PerfectQ]
PerfectSearch[10000]

{6,28,496,8128}


See also: An Introduction to Programming with Mathematica

No comments:

Post a Comment