# Finding all the perfect integers below 10000 [closed]

I have a homework problem about perfect numbers. I simply did it, but I need to use Divisors, Most, Plus, Apply and AppendTo commands.

Here is my work; https://i.hizliresim.com/Mv5nL7.jpg

• We are awaiting your code to be inserted into your question in a form that we can copy and paste into Mathematica. Commented Jun 2, 2017 at 1:28
• Duplicate of this question? Commented Jun 2, 2017 at 1:59
• Possible duplicate of Perfect numbers Commented Jun 2, 2017 at 4:01
• Select[Range[10^4], Total[Divisors@#] == 2 # &] Divisors[6] Most[{1, 2, 3, 6}] Apply[Plus, Divisors[6]] Commented Jun 2, 2017 at 18:03

You can avoid all the functions you mentioned.

src = " #include \"WolframLibrary.h\"

mint isPerfect(mint num){
mint div_sum = 1;
for (mint i=2; i*i<=num; i++)
if (num%i==0) div_sum += i + num/i;
if (div_sum - num) return 0; return 1;
}

DLLEXPORT int getPerfectNumber(WolframLibraryData libData, mint \
Argc, MArgument *Args, MArgument Res) {
mint limit = MArgument_getInteger(Args[0]), res[100], res_count \
= 0;
for (int i = 2; i <=limit; i+=2)
if (isPerfect(i)) res[res_count++] = i;
MTensor out;
mint out_dims[1];
out_dims[0]=res_count;
mint* out_data;
int err;
err = libData->MTensor_new(MType_Integer, 1, out_dims, &out);
out_data = libData->MTensor_getIntegerData(out);
for (int i = 0; i < res_count; ++i)
out_data[i] = res[i];
MArgument_setMTensor(Res,out);
return LIBRARY_NO_ERROR;
}";
Needs["CCompilerDriver"]
lib = CreateLibrary[src, "getPerfectNumber"];
getPerfectNumber =
"getPerfectNumber", {Integer}, {Integer, 1}];
getPerfectNumber[10000]

• thank you but i need the all functions. Commented Jun 2, 2017 at 18:04
PerfectTest[n_Integer] := Total[Divisors[n]] == 2 n;

Select[Range[1000], PerfectTest]


(*

{6, 28, 496}

*)

• thank you, but i did it already. I need to use Divisors, Most, Plus, Apply and AppendTo commands. Commented Jun 2, 2017 at 18:06
f[n_] := Module[{p = MersennePrimeExponent[n]}, 2^(p - 1) (2^p - 1)]
j = 1; pn = {};
While[f[j] < 10000, AppendTo[pn, f[j]]; j++]
pn
`
• Is it definition of Divisors? Commented Jun 2, 2017 at 18:05