Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions
Sequence: smallest number greater than previous term with exactly n divisors (view source)
Revision as of 19:14, 2 December 2021
, 2 years ago→{{header|ALGOL 68}}: Small optimisation and tweak the output
(→{{header|ALGOL W}}: Tweak) |
(→{{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 ) <
IF n MOD i = 0 THEN count +:= 2 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:"
INT next := 1;
FOR i WHILE next <= max DO
IF next = count divisors( i ) THEN
print( ( " ", whole( i, 0 )
next +:= 1
FI
OD
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>
|