Proper divisors: Difference between revisions

Added XPL0 example.
(→‎Filter solution: Clean-up.)
(Added XPL0 example.)
Line 6,003:
The number in the range [1, 20000] with the most proper divisors is:
15120 which has 79 proper divisors.
</pre>
 
=={{header|XPL0}}==
<lang XPL0>func PropDiv(N, Show); \Count and optionally show proper divisors of N
int N, Show, D, C;
[C:= 0;
if N > 1 then
[D:= 1;
repeat if rem(N/D) = 0 then
[C:= C+1;
if Show then
[if D > 1 then ChOut(0, ^ );
IntOut(0, D);
];
];
D:= D+1;
until D >= N;
];
return C;
];
 
int N, SN, Cnt, Max;
[for N:= 1 to 10 do
[ChOut(0, ^[); PropDiv(N, true); ChOut(0, ^]);
ChOut(0, ^ );
];
CrLf(0);
 
Max:= 0;
for N:= 1 to 20000 do
[Cnt:= PropDiv(N, false);
if Cnt > Max then
[Max:= Cnt; SN:= N];
];
IntOut(0, SN); ChOut(0, ^ ); IntOut(0, Max); CrLf(0);
]</lang>
 
{{out}}
<pre>
[] [1] [1] [1 2] [1] [1 2 3] [1] [1 2 4] [1 3] [1 2 5]
15120 79
</pre>
 
772

edits