Jump to content

Tau function: Difference between revisions

Added Algol 68
(Add PL/M)
(Added Algol 68)
Line 83:
9 2 4 4 8 2 8 2 6 6 4 2 10 3 6 4 6 2 8 4 8 4 4 2 12 2 4 6 7 4 8 2 6 4
8 2 12 2 4 6 6 4 8 2 10 5 4 2 12 4 4 4 8 2 12 4 6 4 4 4 12 2 6 6 9
</pre>
 
=={{header|ALGOL 68}}==
{{Trans|ALGOL W}}{{Trans|C++}}
<lang algol68>BEGIN # find the count of the divisors of the first 100 positive integers #
# calculates the number of divisors of v #
PROC divisor count = ( INT v )INT:
BEGIN
INT total := 1, n := v;
# Deal with powers of 2 first #
WHILE NOT ODD n DO
total +:= 1;
n OVERAB 2
OD;
# Odd prime factors up to the square root #
FOR p FROM 3 BY 2 WHILE ( p * p ) <= n DO
INT count := 1;
WHILE n MOD p = 0 DO
count +:= 1;
n OVERAB p
OD;
total *:= count
OD;
# If n > 1 then it's prime #
IF n > 1 THEN total *:= 2 FI;
total
END # divisor_count # ;
BEGIN
INT limit = 100;
print( ( "Count of divisors for the first ", whole( limit, 0 ), " positive integers:", newline ) );
FOR n TO limit DO
IF n MOD 20 = 1 THEN print( ( newline ) ) FI;
print( ( whole( divisor count( n ), -4 ) ) )
OD
END
END</lang>
{{out}}
<pre>
1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
4 4 2 8 3 4 4 6 2 8 2 6 4 4 4 9 2 4 4 8
2 8 2 6 6 4 2 10 3 6 4 6 2 8 4 8 4 4 2 12
2 4 6 7 4 8 2 6 4 8 2 12 2 4 6 6 4 8 2 10
5 4 2 12 4 4 4 8 2 12 4 6 4 4 4 12 2 6 6 9
</pre>
 
3,044

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.