41 lines
1.4 KiB
Text
41 lines
1.4 KiB
Text
begin % find the count of the divisors of the first 100 positive integers %
|
|
% calculates the number of divisors of v %
|
|
integer procedure divisor_count( integer value v ) ; begin
|
|
integer total, n, p;
|
|
total := 1; n := v;
|
|
% Deal with powers of 2 first %
|
|
while not odd( n ) do begin
|
|
total := total + 1;
|
|
n := n div 2
|
|
end while_not_odd_n ;
|
|
% Odd prime factors up to the square root %
|
|
p := 3;
|
|
while ( p * p ) <= n do begin
|
|
integer count;
|
|
count := 1;
|
|
while n rem p = 0 do begin
|
|
count := count + 1;
|
|
n := n div p
|
|
end while_n_rem_p_eq_0 ;
|
|
p := p + 2;
|
|
total := total * count
|
|
end while_p_x_p_le_n ;
|
|
% If n > 1 then it's prime %
|
|
if n > 1 then total := total * 2;
|
|
total
|
|
end divisor_count ;
|
|
begin
|
|
integer limit, count, n;
|
|
limit := 100;
|
|
write( i_w := 1, s_w := 0, "The first ", limit, " tau numbers:" );
|
|
count := n := 0;
|
|
while count < limit do begin
|
|
n := n + 1;
|
|
if n rem divisor_count( n ) = 0 then begin
|
|
count := count + 1;
|
|
if count rem 10 = 1 then write( " " );
|
|
writeon( i_w := 5, s_w := 1, n )
|
|
end if_n_rem_divisor_count__n_eq_0
|
|
end while_count_lt_limit
|
|
end
|
|
end.
|