Functions of Divisors
Steven Miller
November 2011

?Divisors

applyfn[tempf_, n_, print_] := Module[{},
list = Divisors[n];
newlist = tempf[list];
sum = Sum[newlist[[k]], {k,1,Length[newlist]-1}];
flast = newlist[[Length[newlist]]];
If[print == True,
{
Print["Divisor list is ", list];
Print["Applying function to proper divisors gives ", sum];
Print["Applying function to number ", n, " is ", flast];
}];
If[sum == flast, Return[1],Return[0]]
];

h[x_] := x^2

applyfn[Identity,28,True]

tester[numdo_] := Module[{},
foundlist = {};
For[n = 1, n ≤ numdo, n++,
{
value = applyfn[Identity,n,False];
If[value == 1, 
{
foundlist = AppendTo[foundlist, n];
Print[n];
}];
If[Mod[n,numdo/20] == 0, Print["We have done ", 100.0 n /numdo, "% and are at ", n, " of ", numdo, "."]];
}];
Print["\nThe perfect numbers up to ", numdo, " are ", foundlist, "."];
];

Timing[tester[1000000]]

Timing[tester[100000000]]