RosettaCodeData/Task/Proper-divisors/Fermat/proper-divisors.fermat
2023-07-01 13:44:08 -04:00

24 lines
688 B
Text

Func Divisors(n) =
[d]:=[(1)]; {start divisor list with just 1, which is a divisor of everything}
for i = 2 to n\2 do {loop through possible divisors of n}
if Divides(i, n) then [d]:=[d]_[(i)] fi
od;
.;
for n = 1 to 10 do
Divisors(n);
!!(n,' ',[d);
od;
record:=0;
champ:=1;
for n=2 to 20000 do
Divisors(n);
m:=Cols[d]; {this gets the length of the array}
if m > record then
champ:=n;
record:=m;
fi;
od;
!!('The number up to 20,000 with the most divisors was ',champ,' with ',record,' divisors.');