Proper divisors: Difference between revisions

→‎{{header|Mathematica}} / {{header|Wolfram Language}}: The solution here was technically correct but not formatted properly. I have cleaned it up.
(→‎{{header|Mathematica}} / {{header|Wolfram Language}}: The solution here was technically correct but not formatted properly. I have cleaned it up.)
Line 256:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
 
{{incorrect|Mathematica|18720 for example is not part of a solution asked for by the task.}}
A Function that yields the proper divisors of an integer n:
Proper divisors of n from 1 to 10
<lang Mathematica>JoinProperDivisors[{{1,n_Integer {}}},/; Table[{n, > 0] := Most@Divisors@n}, {n, 2, 10}]] // Grid;</lang>
 
Proper divisors of n from 1 to 10:
<lang Mathematica>Grid@Table[{n, ProperDivisors[n]}, {n, 1, 10}]</lang>
{{out}}
<pre>1 {}
Line 270 ⟶ 273:
9 {1,3}
10 {1,2,5}</pre>
 
Five numbers <=20000 with the most proper divisors
The number with the most divisors between 1 and 20,000:
<lang Mathematica>Join[{{n, count}}, {#, Length@Most@Divisors@#} & /@
<lang Mathematica>Fold[
Ordering[Table[Length@Most@Divisors[n], {n, 20000}], -5]] // Grid</lang>
Last[SortBy[{#1, {#2, Length@ProperDivisors[#2]}}, Last]] &,
{0, 0},
Range[20000]]</lang>
{{out}}
<pre>n count{18480, 79}</pre>
18720 71
18900 71
19800 71
15120 79
18480 79</pre>
 
=={{header|Perl}}==
Anonymous user