Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
56
Task/Tau-function/Free-Pascal/tau-function.pas
Normal file
56
Task/Tau-function/Free-Pascal/tau-function.pas
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
program Tau_function;
|
||||
{$IFDEF Windows} {$APPTYPE CONSOLE} {$ENDIF}
|
||||
function CountDivisors(n: NativeUint): integer;
|
||||
var
|
||||
q, p, cnt, divcnt: NativeUint;
|
||||
begin
|
||||
divCnt := 1;
|
||||
if n > 1 then
|
||||
begin
|
||||
cnt := 1;
|
||||
while not (Odd(n)) do
|
||||
begin
|
||||
n := n shr 1;
|
||||
divCnt := divCnt+cnt;
|
||||
end;
|
||||
p := 3;
|
||||
while p * p <= n do
|
||||
begin
|
||||
cnt := divCnt;
|
||||
q := n div p;
|
||||
while q * p = n do
|
||||
begin
|
||||
n := q;
|
||||
q := n div p;
|
||||
divCnt := divCnt+cnt;
|
||||
end;
|
||||
Inc(p, 2);
|
||||
end;
|
||||
if n <> 1 then
|
||||
divCnt := divCnt+divCnt;
|
||||
end;
|
||||
CountDivisors := divCnt;
|
||||
end;
|
||||
|
||||
const
|
||||
UPPERLIMIT = 99;
|
||||
colWidth = trunc(ln(UPPERLIMIT)/ln(10))+1;
|
||||
var
|
||||
i: NativeUint;
|
||||
begin
|
||||
writeln('The tau functions for the first ',UPPERLIMIT,' positive integers are:');
|
||||
Write('': colWidth+1);
|
||||
for i := 0 to 9 do
|
||||
Write(i: colWidth, ' ');
|
||||
for i := 0 to UPPERLIMIT do
|
||||
begin
|
||||
if i mod 10 = 0 then
|
||||
begin
|
||||
writeln;
|
||||
Write(i div 10: colWidth, '|');
|
||||
end;
|
||||
Write(CountDivisors(i): colWidth, ' ');
|
||||
end;
|
||||
writeln;
|
||||
{$Ifdef Windows}readln;{$ENDIF}
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue