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

→‎{{header|ALGOL 68}}: Small optimisation and tweak the output
(→‎{{header|ALGOL 68}}: Small optimisation and tweak the output)
Line 160:
 
=={{header|ALGOL 68}}==
{{trans|Go}} with a small optimisation.
<lang algol68>BEGIN
 
PROC count divisors = ( INT n )INT:
BEGIN
INT i2, count := 0;
FOR i WHILE ( i2 := i * i ) <= n DO
IF n MOD i = 0 THEN count +:= 2 FI
count +:= IF i = n OVER i THEN 1 ELSE 2 FI
FI
OD;
IF i2 = n THEN count + 1 ELSE count FI
END # count divisors # ;
INT max = 15;
 
print( ( "The first ", whole( max, 0 ), " terms of the sequence are:", newline ) );
INT next := 1;
FOR i WHILE next <= max DO
IF next = count divisors( i ) THEN
print( ( " ", whole( i, 0 ), " " ) );
next +:= 1
FI
OD;
print( ( newline, newline ) )
 
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
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624
</pre>
 
3,021

edits