Proper divisors: Difference between revisions

add fermat
(add fermat)
Line 2,272:
15120 with 79 divisors.
</pre>
 
=={{header|Fermat}}==
<lang fermat>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.');</lang>
 
{{out}}<pre>
1 1
2 1
3 1
4 1, 2
5 1
6 1, 2, 3
7 1
8 1, 2, 4
9 1, 3
10 1, 2, 5
The number up to 20,000 with the most divisors was 15120 with 79 divisors.</pre>
 
=={{header|Fortran}}==
781

edits