Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions

Added Algol W
(Added solution for Action!)
(Added Algol W)
Line 191:
The first 15 terms of the sequence are:
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624
</pre>
 
=={{header|ALGOL W}}==
{{Trans|Go}}...via Algol 68 and with a small optimisation.
<lang pascal>begin
integer max, next, i;
 
integer procedure countDivisors ( Integer value n ) ;
begin
integer count, i;
count := 0;
i := 1;
while i * i < n do begin
if n rem i = 0 then count := count + 2;
i := i + 1
end;
if i * i = n then count + 1 else count
end countDivisors ;
 
max := 15;
write( i_w := 1, s_w := 0, "The first ", max, " terms of the sequence are: " );
i := next := 1;
while next <= max do begin
if next = countDivisors( i ) then begin
writeon( i_w := 1, s_w := 0, " ", i );
next := next + 1
end;
i := i + 1
end;
write()
end.</lang>
{{out}}
<pre>
The first 15 terms of the sequence are: 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624
</pre>
 
3,022

edits