Tau function: Difference between revisions

From Rosetta Code
Content added Content deleted
(Frink)
m (syntax highlighting fixup automation)
Line 16: Line 16:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F tau(n)
<syntaxhighlight lang="11l">F tau(n)
V ans = 0
V ans = 0
V i = 1
V i = 1
Line 29: Line 29:
R ans
R ans


print((1..100).map(n -> tau(n)))</lang>
print((1..100).map(n -> tau(n)))</syntaxhighlight>


{{out}}
{{out}}
Line 37: Line 37:
=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* program taufunction64.s */
/* program taufunction64.s */
Line 126: Line 126:
/* for this file see task include a file in language AArch64 assembly */
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
<pre>
<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
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
Line 134: Line 134:


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>CARD FUNC DivisorCount(CARD n)
<syntaxhighlight lang="action!">CARD FUNC DivisorCount(CARD n)
CARD result,p,count
CARD result,p,count
Line 171: Line 171:
PrintC(divCount) Put(32)
PrintC(divCount) Put(32)
OD
OD
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Tau_function.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Tau_function.png Screenshot from Atari 8-bit computer]
Line 184: Line 184:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{Trans|ALGOL W}}{{Trans|C++}}
{{Trans|ALGOL W}}{{Trans|C++}}
<lang algol68>BEGIN # find the count of the divisors of the first 100 positive integers #
<syntaxhighlight lang="algol68">BEGIN # find the count of the divisors of the first 100 positive integers #
# calculates the number of divisors of v #
# calculates the number of divisors of v #
PROC divisor count = ( INT v )INT:
PROC divisor count = ( INT v )INT:
Line 215: Line 215:
OD
OD
END
END
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 228: Line 228:
=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
{{Trans|C++}}
{{Trans|C++}}
<lang pascal>begin % find the count of the divisors of the first 100 positive integers %
<syntaxhighlight lang="pascal">begin % find the count of the divisors of the first 100 positive integers %
% calculates the number of divisors of v %
% calculates the number of divisors of v %
integer procedure divisor_count( integer value v ) ; begin
integer procedure divisor_count( integer value v ) ; begin
Line 263: Line 263:
end for_n
end for_n
end
end
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 276: Line 276:
=={{header|APL}}==
=={{header|APL}}==
{{works with|Dyalog APL}}
{{works with|Dyalog APL}}
<lang APL>tau ← 0+.=⍳|⊢
<syntaxhighlight lang="apl">tau ← 0+.=⍳|⊢
tau¨ 5 20⍴⍳100</lang>
tau¨ 5 20⍴⍳100</syntaxhighlight>
{{out}}
{{out}}
<pre>1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre>1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 286: Line 286:


=={{header|AppleScript}}==
=={{header|AppleScript}}==
<lang applescript>on factorCount(n)
<syntaxhighlight lang="applescript">on factorCount(n)
if (n < 1) then return 0
if (n < 1) then return 0
set counter to 2
set counter to 2
Line 309: Line 309:
set output to output as text
set output to output as text
set AppleScript's text item delimiters to astid
set AppleScript's text item delimiters to astid
return output</lang>
return output</syntaxhighlight>


{{output}}
{{output}}
<lang applescript>"Positive divisor counts for integers 1 to 100:
<syntaxhighlight lang="applescript">"Positive divisor counts for integers 1 to 100:
1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
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
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 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
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"</lang>
5 4 2 12 4 4 4 8 2 12 4 6 4 4 4 12 2 6 6 9"</syntaxhighlight>
=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* ARM assembly Raspberry PI */
/* program taufunction.s */
/* program taufunction.s */
Line 411: Line 411:
/***************************************************/
/***************************************************/
.include "../affichage.inc"
.include "../affichage.inc"
</syntaxhighlight>
</lang>
<pre>
<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
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
Line 419: Line 419:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>tau: function [x] -> size factors x
<syntaxhighlight lang="rebol">tau: function [x] -> size factors x


loop split.every:20 1..100 => [
loop split.every:20 1..100 => [
print map & => [pad to :string tau & 3]
print map & => [pad to :string tau & 3]
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 434: Line 434:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>loop 100
<syntaxhighlight lang="autohotkey">loop 100
result .= SubStr(" " Tau(A_Index), -3) . (Mod(A_Index, 10) ? " " : "`n")
result .= SubStr(" " Tau(A_Index), -3) . (Mod(A_Index, 10) ? " " : "`n")
MsgBox % result
MsgBox % result
Line 447: Line 447:
Sort, v, N U D,
Sort, v, N U D,
Return, v
Return, v
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4
<pre> 1 2 2 3 2 4 2 4 3 4
Line 461: Line 461:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f TAU_FUNCTION.AWK
# syntax: GAWK -f TAU_FUNCTION.AWK
BEGIN {
BEGIN {
Line 481: Line 481:
return(count)
return(count)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 499: Line 499:
=={{header|BASIC}}==
=={{header|BASIC}}==
{{trans|C}}
{{trans|C}}
<lang gwbasic>10 DEFINT A-Z
<syntaxhighlight lang="gwbasic">10 DEFINT A-Z
20 FOR I=1 TO 100
20 FOR I=1 TO 100
30 N=I: GOSUB 100
30 N=I: GOSUB 100
Line 516: Line 516:
180 IF P*P<=N GOTO 140
180 IF P*P<=N GOTO 140
190 IF N>1 THEN T=T*2
190 IF N>1 THEN T=T*2
200 RETURN</lang>
200 RETURN</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 526: Line 526:


==={{header|BASIC256}}===
==={{header|BASIC256}}===
<lang BASIC256>print "The tau functions for the first 100 positive integers are:"
<syntaxhighlight lang="basic256">print "The tau functions for the first 100 positive integers are:"
print
print


Line 541: Line 541:
if N mod 10 = 0 then print
if N mod 10 = 0 then print
next N
next N
end</lang>
end</syntaxhighlight>


==={{header|QBasic}}===
==={{header|QBasic}}===
{{works with|QBasic}}
{{works with|QBasic}}
<lang QBasic>PRINT "The tau functions for the first 100 positive integers are:": PRINT
<syntaxhighlight lang="qbasic">PRINT "The tau functions for the first 100 positive integers are:": PRINT


FOR N = 1 TO 100
FOR N = 1 TO 100
Line 559: Line 559:
IF N MOD 10 = 0 THEN PRINT
IF N MOD 10 = 0 THEN PRINT
NEXT N
NEXT N
END</lang>
END</syntaxhighlight>


==={{header|True BASIC}}===
==={{header|True BASIC}}===
<lang qbasic>PRINT "The tau functions for the first 100 positive integers are:"
<syntaxhighlight lang="qbasic">PRINT "The tau functions for the first 100 positive integers are:"
PRINT
PRINT


Line 577: Line 577:
IF REMAINDER (N, 10) = 0 THEN PRINT
IF REMAINDER (N, 10) = 0 THEN PRINT
NEXT N
NEXT N
END</lang>
END</syntaxhighlight>


==={{header|Yabasic}}===
==={{header|Yabasic}}===
<lang yabasic>print "The tau functions for the first 100 positive integers are:\n"
<syntaxhighlight lang="yabasic">print "The tau functions for the first 100 positive integers are:\n"


for N = 1 to 100
for N = 1 to 100
Line 594: Line 594:
if mod(N, 10) = 0 then print : fi
if mod(N, 10) = 0 then print : fi
next N
next N
end</lang>
end</syntaxhighlight>




=={{header|BCPL}}==
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
<syntaxhighlight lang="bcpl">get "libhdr"


let tau(n) = valof
let tau(n) = valof
Line 623: Line 623:
$( writed(tau(n), 3)
$( writed(tau(n), 3)
if n rem 20 = 0 then wrch('*N')
if n rem 20 = 0 then wrch('*N')
$)</lang>
$)</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 632: Line 632:


=={{header|BQN}}==
=={{header|BQN}}==
<lang bqn>Tau ← +´0=(1+↕)|⊢
<syntaxhighlight lang="bqn">Tau ← +´0=(1+↕)|⊢
Tau¨ 5‿20⥊1+↕100</lang>
Tau¨ 5‿20⥊1+↕100</syntaxhighlight>
{{out}}
{{out}}
<pre>┌─
<pre>┌─
Line 645: Line 645:
=={{header|C}}==
=={{header|C}}==
{{trans|C++}}
{{trans|C++}}
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


// See https://en.wikipedia.org/wiki/Divisor_function
// See https://en.wikipedia.org/wiki/Divisor_function
Line 682: Line 682:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Count of divisors for the first 100 positive integers:
<pre>Count of divisors for the first 100 positive integers:
Line 692: Line 692:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iomanip>
<syntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
#include <iostream>


Line 722: Line 722:
std::cout << '\n';
std::cout << '\n';
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 736: Line 736:
=={{header|CLU}}==
=={{header|CLU}}==
{{trans|C}}
{{trans|C}}
<lang clu>tau = proc (n: int) returns (int)
<syntaxhighlight lang="clu">tau = proc (n: int) returns (int)
total: int := 1
total: int := 1
while n//2 = 0 do
while n//2 = 0 do
Line 764: Line 764:
if n//20=0 then stream$putl(po, "") end
if n//20=0 then stream$putl(po, "") end
end
end
end start_up</lang>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 774: Line 774:
=={{header|COBOL}}==
=={{header|COBOL}}==
{{trans|C}}
{{trans|C}}
<lang cobol> IDENTIFICATION DIVISION.
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. TAU-FUNCTION.
PROGRAM-ID. TAU-FUNCTION.


Line 838: Line 838:
ADD 1 TO F-COUNT,
ADD 1 TO F-COUNT,
GO TO ODD-FACTOR-LOOP.
GO TO ODD-FACTOR-LOOP.
MULTIPLY F-COUNT BY TOTAL.</lang>
MULTIPLY F-COUNT BY TOTAL.</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 848: Line 848:
=={{header|Cowgol}}==
=={{header|Cowgol}}==
{{trans|C}}
{{trans|C}}
<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";


typedef N is uint8;
typedef N is uint8;
Line 886: Line 886:
if n % 20 == 0 then print_nl(); end if;
if n % 20 == 0 then print_nl(); end if;
n := n + 1;
n := n + 1;
end loop;</lang>
end loop;</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 896: Line 896:
=={{header|D}}==
=={{header|D}}==
{{trans|C++}}
{{trans|C++}}
<lang d>import std.stdio;
<syntaxhighlight lang="d">import std.stdio;


// See https://en.wikipedia.org/wiki/Divisor_function
// See https://en.wikipedia.org/wiki/Divisor_function
Line 929: Line 929:
}
}
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Count of divisors for the first 100 positive integers:
<pre>Count of divisors for the first 100 positive integers:
Line 941: Line 941:
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}
{{Trans|Go}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Tau_function;
program Tau_function;


Line 979: Line 979:
end;
end;
readln;
readln;
end.</lang>
end.</syntaxhighlight>


=={{header|Draco}}==
=={{header|Draco}}==
<lang draco>proc nonrec tau(word n) word:
<syntaxhighlight lang="draco">proc nonrec tau(word n) word:
word count, total, p;
word count, total, p;
total := 1;
total := 1;
Line 1,011: Line 1,011:
if n%20=0 then writeln() fi
if n%20=0 then writeln() fi
od
od
corp</lang>
corp</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 1,023: Line 1,023:
{{trans|Swift}}
{{trans|Swift}}


<lang dyalect>func divisorCount(number) {
<syntaxhighlight lang="dyalect">func divisorCount(number) {
var n = number
var n = number
var total = 1
var total = 1
Line 1,055: Line 1,055:
print(divisorCount(number: n).ToString().PadLeft(2, ' ') + " ", terminator: "")
print(divisorCount(number: n).ToString().PadLeft(2, ' ') + " ", terminator: "")
print() when n % 20 == 0
print() when n % 20 == 0
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,068: Line 1,068:
=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
This task uses [[Extensible_prime_generator#The_functions|Extensible Prime Generator (F#)]].<br>
This task uses [[Extensible_prime_generator#The_functions|Extensible Prime Generator (F#)]].<br>
<lang fsharp>
<syntaxhighlight lang="fsharp">
// Tau function. Nigel Galloway: March 10th., 2021
// Tau function. Nigel Galloway: March 10th., 2021
let tau u=let P=primes32()
let tau u=let P=primes32()
Line 1,075: Line 1,075:
let n=Seq.head P in fG 1 n 1 1 n
let n=Seq.head P in fG 1 n 1 1 n
[1..100]|>Seq.iter(tau>>printf "%d "); printfn ""
[1..100]|>Seq.iter(tau>>printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,083: Line 1,083:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
{{works with|Factor|0.99 2020-08-14}}
<lang factor>USING: assocs formatting io kernel math math.primes.factors
<syntaxhighlight lang="factor">USING: assocs formatting io kernel math math.primes.factors
math.ranges sequences sequences.extras ;
math.ranges sequences sequences.extras ;


Line 1,099: Line 1,099:
[ "%2d |" printf ]
[ "%2d |" printf ]
[ dup 10 + [a,b) [ tau "%4d" printf ] each nl ] bi
[ dup 10 + [a,b) [ tau "%4d" printf ] each nl ] bi
] each</lang>
] each</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,119: Line 1,119:


=={{header|Fermat}}==
=={{header|Fermat}}==
<lang>Func Tau(t) =
<syntaxhighlight lang="text">Func Tau(t) =
if t<3 then Return(t) else
if t<3 then Return(t) else
numdiv:=2;
numdiv:=2;
Line 1,131: Line 1,131:
for i = 1 to 100 do
for i = 1 to 100 do
!(Tau(i),' ');
!(Tau(i),' ');
od;</lang>
od;</syntaxhighlight>
{{out}}<pre>
{{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>
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>
Line 1,137: Line 1,137:
=={{header|Forth}}==
=={{header|Forth}}==
{{trans|C++}}
{{trans|C++}}
<lang forth>: divisor_count ( n -- n )
<syntaxhighlight lang="forth">: divisor_count ( n -- n )
1 >r
1 >r
begin
begin
Line 1,169: Line 1,169:


100 print_divisor_counts
100 print_divisor_counts
bye</lang>
bye</syntaxhighlight>


{{out}}
{{out}}
Line 1,182: Line 1,182:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>function numdiv( n as uinteger ) as uinteger
<syntaxhighlight lang="freebasic">function numdiv( n as uinteger ) as uinteger
dim as uinteger c = 1
dim as uinteger c = 1
for i as uinteger = 1 to (n+1)\2
for i as uinteger = 1 to (n+1)\2
Line 1,194: Line 1,194:
print numdiv(i),
print numdiv(i),
if i mod 10 = 0 then print
if i mod 10 = 0 then print
next i</lang>
next i</syntaxhighlight>
{{out}}
{{out}}
<pre>1 2 2 3 2 4 2 4 3 4
<pre>1 2 2 3 2 4 2 4 3 4
Line 1,208: Line 1,208:


=={{header|Frink}}==
=={{header|Frink}}==
<lang frink>tau[n] := length[allFactors[n]]
<syntaxhighlight lang="frink">tau[n] := length[allFactors[n]]


for n=1 to 100
for n=1 to 100
print[tau[n] + " "]
print[tau[n] + " "]
println[]</lang>
println[]</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,219: Line 1,219:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 1,251: Line 1,251:
}
}
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,264: Line 1,264:


=={{header|GW-BASIC}}==
=={{header|GW-BASIC}}==
<lang gwbasic>10 FOR N = 1 TO 100
<syntaxhighlight lang="gwbasic">10 FOR N = 1 TO 100
20 IF N < 3 THEN T=N: GOTO 70
20 IF N < 3 THEN T=N: GOTO 70
30 T=2
30 T=2
Line 1,272: Line 1,272:
70 PRINT T;
70 PRINT T;
80 IF N MOD 10 = 0 THEN PRINT
80 IF N MOD 10 = 0 THEN PRINT
90 NEXT N</lang>
90 NEXT N</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,288: Line 1,288:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang Haskell>tau :: Integral a => a -> a
<syntaxhighlight lang="haskell">tau :: Integral a => a -> a
tau n | n <= 0 = error "Not a positive integer"
tau n | n <= 0 = error "Not a positive integer"
tau n = go 0 (1, 1)
tau n = go 0 (1, 1)
Line 1,299: Line 1,299:
| otherwise = go r (yo $ i + 1)
| otherwise = go r (yo $ i + 1)


main = print $ map tau [1..100]</lang>
main = print $ map tau [1..100]</syntaxhighlight>
{{out}}
{{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>
<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>


=={{header|J}}==
=={{header|J}}==
<lang j>tau =: [:+/0=>:@i.|]
<syntaxhighlight lang="j">tau =: [:+/0=>:@i.|]
echo tau"0 [5 20$>:i.100
echo tau"0 [5 20$>:i.100
exit ''</lang>
exit ''</syntaxhighlight>
{{out}}
{{out}}
<pre>1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre>1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 1,316: Line 1,316:
=={{header|Java}}==
=={{header|Java}}==
{{trans|D}}
{{trans|D}}
<lang java>public class TauFunction {
<syntaxhighlight lang="java">public class TauFunction {
private static long divisorCount(long n) {
private static long divisorCount(long n) {
long total = 1;
long total = 1;
Line 1,348: Line 1,348:
}
}
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Count of divisors for the first 100 positive integers:
<pre>Count of divisors for the first 100 positive integers:
Line 1,362: Line 1,362:


'''Preliminaries'''
'''Preliminaries'''
See https://rosettacode.org/wiki/Sum_of_divisors#jq for the definition of `divisors` used here.<lang jq>def count(s): reduce s as $x (0; .+1);
See https://rosettacode.org/wiki/Sum_of_divisors#jq for the definition of `divisors` used here.<syntaxhighlight lang="jq">def count(s): reduce s as $x (0; .+1);


# For pretty-printing
# For pretty-printing
Line 1,369: Line 1,369:
n;
n;


def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;</lang>
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;</syntaxhighlight>
'''The task'''
'''The task'''
<lang jq>[range(1;101) | count(divisors)]
<syntaxhighlight lang="jq">[range(1;101) | count(divisors)]
| nwise(10) | map(lpad(4)) | join("")</lang>
| nwise(10) | map(lpad(4)) | join("")</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,389: Line 1,389:
=={{header|Julia}}==
=={{header|Julia}}==
Recycles code from http://www.rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors#Julia
Recycles code from http://www.rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors#Julia
<lang julia>using Primes
<syntaxhighlight lang="julia">using Primes


function numfactors(n)
function numfactors(n)
Line 1,402: Line 1,402:
print(rpad(numfactors(i), 3), i % 25 == 0 ? " \n" : " ")
print(rpad(numfactors(i), 3), i % 25 == 0 ? " \n" : " ")
end
end
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<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
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
Line 1,412: Line 1,412:
=={{header|Lua}}==
=={{header|Lua}}==
{{trans|Java}}
{{trans|Java}}
<lang lua>function divisorCount(n)
<syntaxhighlight lang="lua">function divisorCount(n)
local total = 1
local total = 1
-- Deal with powers of 2 first
-- Deal with powers of 2 first
Line 1,444: Line 1,444:
print()
print()
end
end
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>Count of divisors for the first 100 positive integers:
<pre>Count of divisors for the first 100 positive integers:
Line 1,454: Line 1,454:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>DivisorSum[#, 1 &] & /@ Range[100]</lang>
<syntaxhighlight lang="mathematica">DivisorSum[#, 1 &] & /@ Range[100]</syntaxhighlight>
{{out}}
{{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>
<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>
Line 1,460: Line 1,460:
=={{header|Modula-2}}==
=={{header|Modula-2}}==
{{trans|C}}
{{trans|C}}
<lang modula2>MODULE TauFunc;
<syntaxhighlight lang="modula2">MODULE TauFunc;
FROM InOut IMPORT WriteCard, WriteLn;
FROM InOut IMPORT WriteCard, WriteLn;


Line 1,492: Line 1,492:
IF i MOD 20 = 0 THEN WriteLn END
IF i MOD 20 = 0 THEN WriteLn END
END
END
END TauFunc.</lang>
END TauFunc.</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 1,501: Line 1,501:


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>import math, strutils
<syntaxhighlight lang="nim">import math, strutils


func divcount(n: Natural): Natural =
func divcount(n: Natural): Natural =
Line 1,512: Line 1,512:
for i in 1..100:
for i in 1..100:
stdout.write ($divcount(i)).align(3)
stdout.write ($divcount(i)).align(3)
if i mod 20 == 0: echo()</lang>
if i mod 20 == 0: echo()</syntaxhighlight>


{{out}}
{{out}}
Line 1,523: Line 1,523:


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>vector(100,X,numdiv(X))</lang>
<syntaxhighlight lang="parigp">vector(100,X,numdiv(X))</syntaxhighlight>
{{out}}<pre>
{{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>
[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>
Line 1,529: Line 1,529:
=={{header|Pascal}}==
=={{header|Pascal}}==
{{works with|Extended Pascal}}
{{works with|Extended Pascal}}
<lang pascal>program tauFunction(output);
<syntaxhighlight lang="pascal">program tauFunction(output);


type
type
Line 1,571: Line 1,571:
writeLn(f:8, ') = ', tau(i):5)
writeLn(f:8, ') = ', tau(i):5)
end
end
end.</lang>
end.</syntaxhighlight>
==={{header|Free Pascal}}===
==={{header|Free Pascal}}===
{{works with|Free Pascal}} and on TIO.RUN. Only test 0..99 for a nicer table.
{{works with|Free Pascal}} and on TIO.RUN. Only test 0..99 for a nicer table.
<lang pascal>program Tau_function;
<syntaxhighlight lang="pascal">program Tau_function;
{$IFDEF Windows} {$APPTYPE CONSOLE} {$ENDIF}
{$IFDEF Windows} {$APPTYPE CONSOLE} {$ENDIF}
function CountDivisors(n: NativeUint): integer;
function CountDivisors(n: NativeUint): integer;
Line 1,629: Line 1,629:
writeln;
writeln;
{$Ifdef Windows}readln;{$ENDIF}
{$Ifdef Windows}readln;{$ENDIF}
end.</lang>
end.</syntaxhighlight>
{{out|TIO.RUN}}
{{out|TIO.RUN}}
<pre>
<pre>
Line 1,647: Line 1,647:
=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use feature 'say';
use feature 'say';
Line 1,656: Line 1,656:


say "Tau function - first 100:\n" .
say "Tau function - first 100:\n" .
((sprintf "@{['%4d' x 100]}", @x[0..100-1]) =~ s/(.{80})/$1\n/gr);</lang>
((sprintf "@{['%4d' x 100]}", @x[0..100-1]) =~ s/(.{80})/$1\n/gr);</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 1,666: Line 1,666:
=={{header|Phix}}==
=={{header|Phix}}==
=== imperative ===
=== imperative ===
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))})</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,682: Line 1,682:
=== functional ===
=== functional ===
same output
same output
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #004080;">sequence</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">100</span><span style="color: #0000FF;">),{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}}),</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">100</span><span style="color: #0000FF;">),{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}}),</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">r</span><span style="color: #0000FF;">}),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">r</span><span style="color: #0000FF;">}),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">))</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PL/I}}==
=={{header|PL/I}}==
{{trans|C}}
{{trans|C}}
<lang pli>taufunc: procedure options(main);
<syntaxhighlight lang="pli">taufunc: procedure options(main);
tau: procedure(nn) returns(fixed);
tau: procedure(nn) returns(fixed);
declare (n, nn, tot, pf, cnt) fixed;
declare (n, nn, tot, pf, cnt) fixed;
Line 1,711: Line 1,711:
if mod(n,20)=0 then put skip;
if mod(n,20)=0 then put skip;
end;
end;
end taufunc;</lang>
end taufunc;</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 1,722: Line 1,722:
=={{header|PL/M}}==
=={{header|PL/M}}==
{{trans|C}}
{{trans|C}}
<lang pli>100H:
<syntaxhighlight lang="pli">100H:


/* CP/M BDOS FUNCTIONS */
/* CP/M BDOS FUNCTIONS */
Line 1,771: Line 1,771:
END;
END;
CALL EXIT;
CALL EXIT;
EOF</lang>
EOF</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 1,780: Line 1,780:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>If OpenConsole()
<syntaxhighlight lang="purebasic">If OpenConsole()
For i=1 To 100
For i=1 To 100
If i<3 : Print(RSet(Str(i),4)) : Continue :EndIf
If i<3 : Print(RSet(Str(i),4)) : Continue :EndIf
Line 1,790: Line 1,790:
Input()
Input()
EndIf
EndIf
End</lang>
End</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4
<pre> 1 2 2 3 2 4 2 4 3 4
Line 1,805: Line 1,805:
=={{header|Python}}==
=={{header|Python}}==
===Using prime factorization===
===Using prime factorization===
<lang Python>def factorize(n):
<syntaxhighlight lang="python">def factorize(n):
assert(isinstance(n, int))
assert(isinstance(n, int))
if n < 0:
if n < 0:
Line 1,837: Line 1,837:


if __name__ == "__main__":
if __name__ == "__main__":
print([tau(n) for n in range(1,101)])</lang>
print([tau(n) for n in range(1,101)])</syntaxhighlight>
===Finding divisors efficiently===
===Finding divisors efficiently===
<lang Python>def tau(n):
<syntaxhighlight lang="python">def tau(n):
assert(isinstance(n, int) and 0 < n)
assert(isinstance(n, int) and 0 < n)
ans, i, j = 0, 1, 1
ans, i, j = 0, 1, 1
Line 1,852: Line 1,852:


if __name__ == "__main__":
if __name__ == "__main__":
print([tau(n) for n in range(1,101)])</lang>
print([tau(n) for n in range(1,101)])</syntaxhighlight>
{{out}}
{{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>
<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>
Line 1,859: Line 1,859:
Yet another exercise in defining a '''divisors''' function.
Yet another exercise in defining a '''divisors''' function.


<lang python>'''The number of divisors of n'''
<syntaxhighlight lang="python">'''The number of divisors of n'''


from itertools import count, islice
from itertools import count, islice
Line 1,945: Line 1,945:
# MAIN ---
# MAIN ---
if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>
{{Out}}
{{Out}}
<pre> 1 2 2 3 2 4 2 4 3 4
<pre> 1 2 2 3 2 4 2 4 3 4
Line 1,963: Line 1,963:




<lang Quackery> [ factors size ] is tau ( n --> n )
<syntaxhighlight lang="quackery"> [ factors size ] is tau ( n --> n )


[] []
[] []
Line 1,969: Line 1,969:
witheach [ number$ nested join ]
witheach [ number$ nested join ]
70 wrap$
70 wrap$
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,980: Line 1,980:
=={{header|R}}==
=={{header|R}}==
This only takes one line.
This only takes one line.
<lang rsplus>lengths(sapply(1:100, function(n) c(Filter(function(x) n %% x == 0, seq_len(n %/% 2)), n)))</lang>
<syntaxhighlight lang="rsplus">lengths(sapply(1:100, function(n) c(Filter(function(x) n %% x == 0, seq_len(n %/% 2)), n)))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Yet more tasks that are tiny variations of each other. [[Tau function]], [[Tau number]], [[Sum of divisors]] and [[Product of divisors]] all use code with minimal changes. What the heck, post 'em all.
Yet more tasks that are tiny variations of each other. [[Tau function]], [[Tau number]], [[Sum of divisors]] and [[Product of divisors]] all use code with minimal changes. What the heck, post 'em all.


<lang perl6>use Prime::Factor:ver<0.3.0+>;
<syntaxhighlight lang="raku" line>use Prime::Factor:ver<0.3.0+>;
use Lingua::EN::Numbers;
use Lingua::EN::Numbers;


Line 2,002: Line 2,002:
say "\nDivisor products - first 100:\n", # ID
say "\nDivisor products - first 100:\n", # ID
(1..*).map({ [×] .&divisors })[^100]\ # the task
(1..*).map({ [×] .&divisors })[^100]\ # the task
.batch(5)».&comma».fmt("%16s").join("\n"); # display formatting</lang>
.batch(5)».&comma».fmt("%16s").join("\n"); # display formatting</syntaxhighlight>
{{out}}
{{out}}
<pre>Tau function - first 100:
<pre>Tau function - first 100:
Line 2,053: Line 2,053:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program counts the number of divisors (tau, or sigma_0) up to and including N.*/
<syntaxhighlight lang="rexx">/*REXX program counts the number of divisors (tau, or sigma_0) up to and including N.*/
parse arg LO HI cols . /*obtain optional argument from the CL.*/
parse arg LO HI cols . /*obtain optional argument from the CL.*/
if LO=='' | LO=="," then LO= 1 /*Not specified? Then use the default.*/
if LO=='' | LO=="," then LO= 1 /*Not specified? Then use the default.*/
Line 2,084: Line 2,084:
end /* ___ */
end /* ___ */
else if j*j>x then leave /*only divide up to √ x */
else if j*j>x then leave /*only divide up to √ x */
end /*j*/; return # /* [↑] this form of DO loop is faster.*/</lang>
end /*j*/; return # /* [↑] this form of DO loop is faster.*/</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
Line 2,098: Line 2,098:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
see "The tau functions for the first 100 positive integers are:" + nl
see "The tau functions for the first 100 positive integers are:" + nl


Line 2,122: Line 2,122:
see "" + tau + " "
see "" + tau + " "
end
end
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 2,140: Line 2,140:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>require 'prime'
<syntaxhighlight lang="ruby">require 'prime'


def tau(n) = n.prime_division.inject(1){|res, (d, exp)| res *= exp + 1}
def tau(n) = n.prime_division.inject(1){|res, (d, exp)| res *= exp + 1}


(1..100).map{|n| tau(n).to_s.rjust(3) }.each_slice(20){|ar| puts ar.join}
(1..100).map{|n| tau(n).to_s.rjust(3) }.each_slice(20){|ar| puts ar.join}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
<pre> 1 2 2 3 2 4 2 4 3 4 2 6 2 4 4 5 2 6 2 6
Line 2,155: Line 2,155:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>// returns the highest power of i that is a factor of n,
<syntaxhighlight lang="rust">// returns the highest power of i that is a factor of n,
// and n divided by that power of i
// and n divided by that power of i
fn factor_exponent(n: i32, i: i32) -> (i32, i32) {
fn factor_exponent(n: i32, i: i32) -> (i32, i32) {
Line 2,180: Line 2,180:
print!("{} ", tau(i));
print!("{} ", tau(i));
}
}
}</lang>
}</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 2,188: Line 2,188:
=={{header|Sidef}}==
=={{header|Sidef}}==
Built-in:
Built-in:
<lang ruby>say { .sigma0 }.map(1..100).join(' ')</lang>
<syntaxhighlight lang="ruby">say { .sigma0 }.map(1..100).join(' ')</syntaxhighlight>


{{out}}
{{out}}
Line 2,196: Line 2,196:


=={{header|Swift}}==
=={{header|Swift}}==
<lang swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


// See https://en.wikipedia.org/wiki/Divisor_function
// See https://en.wikipedia.org/wiki/Divisor_function
Line 2,232: Line 2,232:
print()
print()
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,245: Line 2,245:


=={{header|Tiny BASIC}}==
=={{header|Tiny BASIC}}==
<lang tinybasic> LET N = 0
<syntaxhighlight lang="tinybasic"> LET N = 0
10 LET N = N + 1
10 LET N = N + 1
IF N < 3 THEN GOTO 100
IF N < 3 THEN GOTO 100
Line 2,257: Line 2,257:
END
END
100 LET T = N
100 LET T = N
GOTO 30</lang>
GOTO 30</syntaxhighlight>




=={{header|Verilog}}==
=={{header|Verilog}}==
<lang Verilog>module main;
<syntaxhighlight lang="verilog">module main;
integer N, T, A;
integer N, T, A;
Line 2,280: Line 2,280:
$finish ;
$finish ;
end
end
endmodule</lang>
endmodule</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
<syntaxhighlight lang="ecmascript">import "/math" for Int
import "/fmt" for Fmt
import "/fmt" for Fmt


Line 2,292: Line 2,292:
Fmt.write("$2d ", Int.divisors(i).count)
Fmt.write("$2d ", Int.divisors(i).count)
if (i % 20 == 0) System.print()
if (i % 20 == 0) System.print()
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,305: Line 2,305:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>int N, D, C;
<syntaxhighlight lang="xpl0">int N, D, C;
[Format(3, 0);
[Format(3, 0);
for N:= 1 to 100 do
for N:= 1 to 100 do
Line 2,314: Line 2,314:
if rem(N/20) = 0 then CrLf(0);
if rem(N/20) = 0 then CrLf(0);
];
];
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}

Revision as of 18:09, 28 August 2022

Task
Tau function
You are encouraged to solve this task according to the task description, using any language you may know.

Given a positive integer, count the number of its positive divisors.


Task

Show the result for the first   100   positive integers.


Related task



11l

Translation of: Python
F tau(n)
   V ans = 0
   V i = 1
   V j = 1
   L i * i <= n
      I 0 == n % i
         ans++
         j = n I/ i
         I j != i
            ans++
      i++
   R ans

print((1..100).map(n -> tau(n)))
Output:
[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]

AArch64 Assembly

Works with: as version Raspberry Pi 3B version Buster 64 bits
or android 64 bits with application Termux
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/*  program taufunction64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
.equ MAXI,      100
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
sMessResult:        .asciz " @ "
szCarriageReturn:   .asciz "\n"
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss  
sZoneConv:                  .skip 24
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                             // entry of program 
    mov x0,#1                     // factor number one
    bl displayResult
    mov x0,#2                     // factor number two
    bl displayResult
    mov x2,#3                     // begin number three
1:                                // begin loop 
    mov x5,#2                     // divisor counter
    mov x4,#2                     // first divisor 1
2:
    udiv x0,x2,x4                 // compute divisor 2
    msub x3,x0,x4,x2              // remainder
    cmp x3,#0
    bne 3f                        // remainder = 0 ?
    cmp x0,x4                     // same divisor ?
    add x3,x5,1
    add x6,x5,2
    csel x5,x3,x6,eq
3:
    add x4,x4,#1                  // increment divisor
    cmp x4,x0                     // divisor 1  < divisor 2
    blt 2b                        // yes -> loop
    
    mov x0,x5                     // equal -> display
    bl displayResult

    add x2,x2,1
    cmp x2,MAXI                   // end ?
    bls 1b                        // no -> loop
 
    ldr x0,qAdrszCarriageReturn
    bl affichageMess
 
100:                              // standard end of the program 
    mov x0, #0                    // return code
    mov x8, #EXIT                 // request to exit program
    svc #0                        // perform the system call
qAdrszCarriageReturn:        .quad szCarriageReturn
/***************************************************/
/*   display message number                        */
/***************************************************/
/* x0 contains the number            */
displayResult:
    stp x1,lr,[sp,-16]!      // save  registres
    ldr x1,qAdrsZoneConv
    bl conversion10          // call décimal conversion
    strb wzr,[x1,x0]
    ldr x0,qAdrsMessResult
    ldr x1,qAdrsZoneConv     // insert conversion in message
    bl strInsertAtCharInc
    bl affichageMess         // display message
    ldp x1,lr,[sp],16        // restaur des  2 registres
    ret
qAdrsMessResult:     .quad sMessResult
qAdrsZoneConv:       .quad sZoneConv 
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
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

Action!

CARD FUNC DivisorCount(CARD n)
  CARD result,p,count
  
  result=1
  WHILE (n&1)=0
  DO
    result==+1
    n=n RSH 1
  OD

  p=3
  WHILE p*p<=n
  DO
    count=1
    WHILE n MOD p=0
    DO
      count==+1
      n==/p
    OD
    result==*count
    p==+2
  OD

  IF n>1 THEN
    result==*2
  FI
RETURN (result)

PROC Main()
  CARD max=[100],n,divCount

  PrintF("Tau function for the first %U numbers%E",max)
  FOR n=1 TO max
  DO
    divCount=DivisorCount(n)
    PrintC(divCount) Put(32)
  OD
RETURN
Output:

Screenshot from Atari 8-bit computer

Tau function for the first 100 numbers

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

ALGOL 68

Translation of: ALGOL W
Translation of: C++
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:" ) );
        FOR n TO limit DO
            IF n MOD 20 = 1 THEN print( ( newline ) ) FI;
            print( ( whole( divisor count( n ), -4 ) ) )
        OD
    END
END
Output:
Count of divisors for the first 100 positive integers:
   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

ALGOL W

Translation of: C++
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 is prime %
        if n > 1 then total := total * 2;
        total
    end divisor_count ;
    begin
        integer limit;
        limit := 100;
        write( i_w := 1, s_w := 0, "Count of divisors for the first ", limit, " positive integers:" );
        for n := 1 until limit do begin
            if n rem 20 = 1 then write();
            writeon( i_w := 3, s_w := 1, divisor_count( n ) )
        end for_n
    end
end.
Output:
Count of divisors for the first 100 positive integers:
  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

APL

Works with: Dyalog APL
tau  0+.=⍳|⊢
tau¨ 5 20⍴⍳100
Output:
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

AppleScript

on factorCount(n)
    if (n < 1) then return 0
    set counter to 2
    set sqrt to n ^ 0.5
    if (sqrt mod 1 = 0) then set counter to 1
    repeat with i from (sqrt div 1) to 2 by -1
        if (n mod i = 0) then set counter to counter + 2
    end repeat
    
    return counter
end factorCount

-- Task code:
local output, n, astid
set output to {"Positive divisor counts for integers 1 to 100:"}
repeat with n from 1 to 100
    if (n mod 20 = 1) then set end of output to linefeed
    set end of output to text -3 thru -1 of ("  " & factorCount(n))
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set output to output as text
set AppleScript's text item delimiters to astid
return output
Output:
"Positive divisor counts for integers 1 to 100:
  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"

ARM Assembly

Works with: as version Raspberry Pi
or android 32 bits with application Termux
/* ARM assembly Raspberry PI  */
/*  program taufunction.s   */
 
 /* REMARK 1 : this program use routines in a include file 
   see task Include a file language arm assembly 
   for the routine affichageMess conversion10 
   see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes                       */
/************************************/
.include "../constantes.inc"
 
.equ MAXI,      100
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
sMessResult:        .asciz " @ "
szCarriageReturn:   .asciz "\n"
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss  
sZoneConv:                  .skip 24
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                             @ entry of program 
    mov r0,#1                     @ factor number one
    bl displayResult
    mov r0,#2                     @ factor number two
    bl displayResult
    mov r2,#3                     @ begin number three
1:                                @ begin loop 
    mov r5,#2                     @ divisor counter
    mov r4,#2                     @ first divisor 1
2:
    udiv r0,r2,r4                 @ compute divisor 2
    mls r3,r0,r4,r2               @ remainder
    cmp r3,#0
    bne 3f                        @ remainder = 0 ?
    cmp r0,r4                     @ same divisor ?
    addeq r5,r5,#1                @ yes increment one
    addne r5,r5,#2                @ no increment two
3:
    add r4,r4,#1                  @ increment divisor
    cmp r4,r0                     @ divisor 1  < divisor 2
    blt 2b                        @ yes -> loop
    
    mov r0,r5                     @ equal -> display
    bl displayResult

    add r2,#1                     @ 
    cmp r2,#MAXI                  @ end ?
    bls 1b                        @ no -> loop
 
    ldr r0,iAdrszCarriageReturn
    bl affichageMess
 
100:                              @ standard end of the program 
    mov r0, #0                    @ return code
    mov r7, #EXIT                 @ request to exit program
    svc #0                        @ perform the system call
iAdrszCarriageReturn:        .int szCarriageReturn
/***************************************************/
/*   display message number                        */
/***************************************************/
/* r0 contains the number            */
displayResult:
    push {r1,r2,lr}               @ save registers 
    ldr r1,iAdrsZoneConv
    bl conversion10               @ call décimal conversion
    mov r2,#0
    strb r2,[r1,r0]
    ldr r0,iAdrsMessResult
    ldr r1,iAdrsZoneConv          @ insert conversion in message
    bl strInsertAtCharInc
    bl affichageMess              @ display message
    pop {r1,r2,pc}                @ restaur des registres
iAdrsMessResult:     .int sMessResult
iAdrsZoneConv:       .int sZoneConv  
/***************************************************/
/*      ROUTINES INCLUDE                           */
/***************************************************/
.include "../affichage.inc"
 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

Arturo

tau: function [x] -> size factors x

loop split.every:20 1..100 => [
    print map & => [pad to :string tau & 3]
]
Output:
  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

AutoHotkey

loop 100
    result .= SubStr("   " Tau(A_Index), -3) . (Mod(A_Index, 10) ? " " : "`n")
MsgBox % result
return

Tau(n){
    return StrSplit(Factors(n), ",").Count()
}
Factors(n) {
    Loop, % floor(sqrt(n))
        v := A_Index = 1 ? 1 "," n : mod(n,A_Index) ? v : v "," A_Index "," n//A_Index
    Sort, v, N U D,
    Return, v
}
Output:
   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

AWK

# syntax: GAWK -f TAU_FUNCTION.AWK
BEGIN {
    print("The tau functions for the first 100 positive integers:")
    for (i=1; i<=100; i++) {
      printf("%2d ",count_divisors(i))
      if (i % 10 == 0) {
        printf("\n")
      }
    }
    exit(0)
}
function count_divisors(n,  count,i) {
    for (i=1; i*i<=n; i++) {
      if (n % i == 0) {
        count += (i == n / i) ? 1 : 2
      }
    }
    return(count)
}
Output:
The tau functions for the first 100 positive integers:
 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

BASIC

Translation of: C
10 DEFINT A-Z
20 FOR I=1 TO 100
30 N=I: GOSUB 100
40 PRINT USING " ##";T;
50 IF I MOD 20=0 THEN PRINT
60 NEXT
70 END
100 T=1
110 IF (N AND 1)=0 THEN N=N\2: T=T+1: GOTO 110
120 P=3
130 GOTO 180
140 C=1
150 IF N MOD P=0 THEN N=N\P: C=C+1: GOTO 150
160 T=T*C
170 P=P+2
180 IF P*P<=N GOTO 140
190 IF N>1 THEN T=T*2
200 RETURN
Output:
  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


BASIC256

print "The tau functions for the first 100 positive integers are:"
print

for N = 1 to 100
	if N < 3 then
		T = N
	else
		T = 2
		for A = 2 to (N+1)\2
			if N mod A = 0 then T += 1
		next A
	end if
	print "  "; T;
	if N mod 10 = 0 then print
next N
end

QBasic

Works with: QBasic
PRINT "The tau functions for the first 100 positive integers are:": PRINT

FOR N = 1 TO 100
    IF N < 3 THEN
        T = N
    ELSE
        T = 2
        FOR A = 2 TO (N + 1) \ 2
            IF N MOD A = 0 THEN T = T + 1
        NEXT A
    END IF
    PRINT USING "###"; T;
    IF N MOD 10 = 0 THEN PRINT
NEXT N
END

True BASIC

PRINT "The tau functions for the first 100 positive integers are:"
PRINT

FOR N = 1 TO 100
    IF N < 3 THEN
       LET T = N
    ELSE
       LET T = 2
       FOR A = 2 TO INT((N+1)/2)
           IF REMAINDER (N, A) = 0 THEN LET T = T + 1
       NEXT A
    END IF
    PRINT " "; T;
    IF REMAINDER (N, 10) = 0 THEN PRINT
NEXT N
END

Yabasic

print "The tau functions for the first 100 positive integers are:\n"

for N = 1 to 100
    if N < 3 then 
        T = N
    else
        T = 2
        for A = 2 to int((N+1)/2)
            if mod(N, A) = 0 then T = T + 1 : fi
        next A
    end if
    print T using "###";
    if mod(N, 10) = 0 then print : fi
next N
end


BCPL

get "libhdr"

let tau(n) = valof
$(  let total = 1 and p = 3
    while (n & 1) = 0 
    $(  total := total + 1
        n := n >> 1
    $)
    while p*p <= n
    $(  let count = 1
        while n rem p = 0
        $(  count := count + 1
            n := n / p
        $)
        total := total * count
        p := p + 2
    $)
    if n>1 then total := total * 2
    resultis total
$)

let start() be
    for n=1 to 100
    $(  writed(tau(n), 3)
        if n rem 20 = 0 then wrch('*N')
    $)
Output:
  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

BQN

Tau  +´0=(1+↕)|⊢
Tau¨ 5201+↕100
Output:
┌─                                               
╵ 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  
                                                ┘

C

Translation of: C++
#include <stdio.h>

// See https://en.wikipedia.org/wiki/Divisor_function
unsigned int divisor_count(unsigned int n) {
    unsigned int total = 1;
    // Deal with powers of 2 first
    for (; (n & 1) == 0; n >>= 1) {
        ++total;
    }
    // Odd prime factors up to the square root
    for (unsigned int p = 3; p * p <= n; p += 2) {
        unsigned int count = 1;
        for (; n % p == 0; n /= p) {
            ++count;
        }
        total *= count;
    }
    // If n > 1 then it's prime
    if (n > 1) {
        total *= 2;
    }
    return total;
}

int main() {
    const unsigned int limit = 100;
    unsigned int n;

    printf("Count of divisors for the first %d positive integers:\n", limit);
    for (n = 1; n <= limit; ++n) {
        printf("%3d", divisor_count(n));
        if (n % 20 == 0) {
            printf("\n");
        }
    }

    return 0;
}
Output:
Count of divisors for the first 100 positive integers:
  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

C++

#include <iomanip>
#include <iostream>

// See https://en.wikipedia.org/wiki/Divisor_function
unsigned int divisor_count(unsigned int n) {
    unsigned int total = 1;
    // Deal with powers of 2 first
    for (; (n & 1) == 0; n >>= 1)
        ++total;
    // Odd prime factors up to the square root
    for (unsigned int p = 3; p * p <= n; p += 2) {
        unsigned int count = 1;
        for (; n % p == 0; n /= p)
            ++count;
        total *= count;
    }
    // If n > 1 then it's prime
    if (n > 1)
        total *= 2;
    return total;
}

int main() {
    const unsigned int limit = 100;
    std::cout << "Count of divisors for the first " << limit << " positive integers:\n";
    for (unsigned int n = 1; n <= limit; ++n) {
        std::cout << std::setw(3) << divisor_count(n);
        if (n % 20 == 0)
            std::cout << '\n';
    }
}
Output:
Count of divisors for the first 100 positive integers:
  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

CLU

Translation of: C
tau = proc (n: int) returns (int)
    total: int := 1
    while n//2 = 0 do
        total := total + 1
        n := n/2
    end
    p: int := 3
    while p*p <= n do
        count: int := 1
        while n//p = 0 do
            count := count + 1
            n := n/p
        end
        total := total * count
        p := p+2
    end
    if n>1 then
        total := total * 2
    end
    return(total)
end tau

start_up = proc ()
    po: stream := stream$primary_output()
    for n: int in int$from_to(1, 100) do
        stream$putright(po, int$unparse(tau(n)), 3)
        if n//20=0 then stream$putl(po, "") end
    end
end start_up
Output:
  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

COBOL

Translation of: C
       IDENTIFICATION DIVISION.
       PROGRAM-ID. TAU-FUNCTION.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 TAU-VARS.
          03 TOTAL              PIC 999.
          03 N                  PIC 999.
          03 FILLER             REDEFINES N.
             05 FILLER          PIC 99.
             05 FILLER          PIC 9.
                88 N-EVEN       VALUES 0, 2, 4, 6, 8.
          03 P                  PIC 999.
          03 P-SQUARED          PIC 999.
          03 N-DIV-P            PIC 999V999.
          03 FILLER             REDEFINES N-DIV-P.
             05 NEXT-N          PIC 999.
             05 FILLER          PIC 999.
                88 DIVISIBLE    VALUE ZERO.
          03 F-COUNT            PIC 999.
       01 CONTROL-VARS.
          03 I                  PIC 999.
       01 OUT-VARS.
          03 OUT-ITM            PIC ZZ9.
          03 OUT-STR            PIC X(80) VALUE SPACES.
          03 OUT-PTR            PIC 99 VALUE 1.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SHOW-TAU VARYING I FROM 1 BY 1
               UNTIL I IS GREATER THAN 100.
           STOP RUN.
       
       SHOW-TAU.
           MOVE I TO N.
           PERFORM TAU.
           MOVE TOTAL TO OUT-ITM.
           STRING OUT-ITM DELIMITED BY SIZE INTO OUT-STR
               WITH POINTER OUT-PTR.
           IF OUT-PTR IS EQUAL TO 61,
               DISPLAY OUT-STR,
               MOVE 1 TO OUT-PTR.

       TAU.
           MOVE 1 TO TOTAL.
           PERFORM POWER-OF-2 UNTIL NOT N-EVEN.
           MOVE ZERO TO P-SQUARED.
           PERFORM ODD-FACTOR THRU ODD-FACTOR-LOOP
               VARYING P FROM 3 BY 2
               UNTIL P-SQUARED IS GREATER THAN N.
           IF N IS GREATER THAN 1,
               MULTIPLY 2 BY TOTAL.
       POWER-OF-2.
           ADD 1 TO TOTAL.
           DIVIDE 2 INTO N.
       ODD-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           MOVE 1 TO F-COUNT.
       ODD-FACTOR-LOOP.
           DIVIDE N BY P GIVING N-DIV-P.
           IF DIVISIBLE,
               MOVE NEXT-N TO N,
               ADD 1 TO F-COUNT,
               GO TO ODD-FACTOR-LOOP.
           MULTIPLY F-COUNT BY TOTAL.
Output:
  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

Cowgol

Translation of: C
include "cowgol.coh";

typedef N is uint8;
sub tau(n: N): (total: N) is
    total := 1;
    while n & 1 == 0 loop
        total := total + 1;
        n := n >> 1;
    end loop;
    var p: N := 3;
    while p*p <= n loop
        var count: N := 1;
        while n%p == 0 loop
            count := count + 1;
            n := n / p;
        end loop;
        total := total * count;
        p := p + 2;
    end loop;
    if n>1 then
        total := total << 1;
    end if;
end sub;

sub print2(n: uint8) is
    print_char(' ');
    if n<10 
        then print_char(' ');
        else print_i8(n/10);
    end if;
    print_i8(n%10);
end sub;

var n: N := 1;
while n <= 100 loop
    print2(tau(n));
    if n % 20 == 0 then print_nl(); end if;
    n := n + 1;
end loop;
Output:
  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

D

Translation of: C++
import std.stdio;

// See https://en.wikipedia.org/wiki/Divisor_function
uint divisor_count(uint n) {
    uint total = 1;
    // Deal with powers of 2 first
    for (; (n & 1) == 0; n >>= 1) {
        ++total;
    }
    // Odd prime factors up to the square root
    for (uint p = 3; p * p <= n; p += 2) {
        uint count = 1;
        for (; n % p == 0; n /= p) {
            ++count;
        }
        total *= count;
    }
    // If n > 1 then it's prime
    if (n > 1) {
        total *= 2;
    }
    return total;
}

void main() {
    immutable limit = 100;
    writeln("Count of divisors for the first ", limit, " positive integers:");
    for (uint n = 1; n <= limit; ++n) {
        writef("%3d", divisor_count(n));
        if (n % 20 == 0) {
            writeln;
        }
    }
}
Output:
Count of divisors for the first 100 positive integers:
  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

Delphi

Translation of: Go
program Tau_function;

{$APPTYPE CONSOLE}

uses
  System.SysUtils;

function CountDivisors(n: Integer): Integer;
begin
  Result := 0;
  var i := 1;
  var k := 2;
  if (n mod 2) = 0 then
    k := 1;

  while i * i <= n do
  begin
    if (n mod i) = 0 then
    begin
      inc(Result);
      var j := n div i;
      if j <> i then
        inc(Result);
    end;
    inc(i, k);
  end;
end;

begin
  writeln('The tau functions for the first 100 positive integers are:');
  for var i := 1 to 100 do
  begin
    write(CountDivisors(i): 2, ' ');
    if (i mod 20) = 0 then
      writeln;
  end;
  readln;
end.

Draco

proc nonrec tau(word n) word:
    word count, total, p;
    total := 1;
    while n & 1 = 0 do
        total := total + 1;
        n := n >> 1
    od;
    p := 3;
    while p*p <= n do
        count := 1;
        while n % p = 0 do
            count := count + 1;
            n := n / p
        od;
        total := total * count;
        p := p + 2
    od;
    if n>1
        then total << 1
        else total
    fi
corp

proc nonrec main() void:
    byte n;
    for n from 1 upto 100 do
        write(tau(n):3);
        if n%20=0 then writeln() fi
    od
corp
Output:
  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

Dyalect

Translation of: Swift
func divisorCount(number) {
    var n = number
    var total = 1
    
    while (n &&& 1) == 0 {
        total += 1
        n >>>= 1
    }
    
    var p = 3
    while p * p <= n {
        var count = 1
        while n % p == 0 {
            count += 1
            n /= p
        }
        total *= count
        p += 2
    }
    
    if n > 1 {
        total *= 2
    }
    
    total
}
 
let limit = 100
print("Count of divisors for the first \(limit) positive integers:")
for n in 1..limit {
    print(divisorCount(number: n).ToString().PadLeft(2, ' ') + " ", terminator: "")
    print() when n % 20 == 0
}
Output:
Count of divisors for the first 100 positive integers:
 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 

F#

This task uses Extensible Prime Generator (F#).

// Tau function. Nigel Galloway: March 10th., 2021
let tau u=let P=primes32()
          let rec fN g=match u%g with 0->g |_->fN(Seq.head P)
          let rec fG n i g e l=match n=u,u%l with (true,_)->e |(_,0)->fG (n*i) i g (e+g)(l*i) |_->let q=fN(Seq.head P) in fG (n*q) q e (e+e) (q*q)
          let n=Seq.head P in fG 1 n 1 1 n
[1..100]|>Seq.iter(tau>>printf "%d "); printfn ""
Output:
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

Factor

Works with: Factor version 0.99 2020-08-14
USING: assocs formatting io kernel math math.primes.factors
math.ranges sequences sequences.extras ;

ERROR: nonpositive n ;

: (tau) ( n -- count )
    group-factors values [ 1 + ] map-product ; inline

: tau ( n -- count ) dup 0 > [ (tau) ] [ nonpositive ] if ;

"Number of divisors for integers 1-100:" print nl
" n   |                   tau(n)" print
"-----+-----------------------------------------" print
1 100 10 <range> [
    [ "%2d   |" printf ]
    [ dup 10 + [a,b) [ tau "%4d" printf ] each nl ] bi
] each
Output:
Number of divisors for integers 1-100:

 n   |                   tau(n)
-----+-----------------------------------------
 1   |   1   2   2   3   2   4   2   4   3   4
11   |   2   6   2   4   4   5   2   6   2   6
21   |   4   4   2   8   3   4   4   6   2   8
31   |   2   6   4   4   4   9   2   4   4   8
41   |   2   8   2   6   6   4   2  10   3   6
51   |   4   6   2   8   4   8   4   4   2  12
61   |   2   4   6   7   4   8   2   6   4   8
71   |   2  12   2   4   6   6   4   8   2  10
81   |   5   4   2  12   4   4   4   8   2  12
91   |   4   6   4   4   4  12   2   6   6   9

Fermat

Func Tau(t) =
    if t<3 then Return(t) else
        numdiv:=2;
        for q = 2 to t\2 do
            if Divides(q, t) then numdiv:=numdiv+1 fi;
        od;
        Return(numdiv);
    fi;
    .;

for i = 1 to 100 do
    !(Tau(i),'  ');
od;
Output:

 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

Forth

Translation of: C++
: divisor_count ( n -- n )
  1 >r
  begin
    dup 2 mod 0=
  while
    r> 1+ >r
    2/
  repeat
  3
  begin
    2dup dup * >=
  while
    1 >r
    begin
      2dup mod 0=
    while
      r> 1+ >r
      tuck / swap
    repeat
    2r> * >r
    2 +
  repeat
  drop 1 > if r> 2* else r> then ;

: print_divisor_counts ( n -- )
  ." Count of divisors for the first " dup . ." positive integers:" cr
  1+ 1 do
    i divisor_count 2 .r
    i 20 mod 0= if cr else space then
  loop ;

100 print_divisor_counts
bye
Output:
Count of divisors for the first 100 positive integers:
 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

FreeBASIC

function numdiv( n as uinteger ) as uinteger
    dim as uinteger c = 1
    for i as uinteger = 1 to (n+1)\2
        if n mod i = 0 then c += 1
    next i
    if n=1 then c-=1
    return c
end function

for i as uinteger = 1 to 100
   print numdiv(i),
   if i mod 10 = 0 then print
next i
Output:
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

Frink

tau[n] := length[allFactors[n]]

for n=1 to 100
   print[tau[n] + " "]
println[]
Output:
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 

Go

package main

import "fmt"

func countDivisors(n int) int {
    count := 0
    i := 1
    k := 2
    if n%2 == 0 {
        k = 1
    }
    for i*i <= n {
        if n%i == 0 {
            count++
            j := n / i
            if j != i {
                count++
            }
        }
        i += k
    }
    return count
}

func main() {
    fmt.Println("The tau functions for the first 100 positive integers are:")
    for i := 1; i <= 100; i++ {
        fmt.Printf("%2d  ", countDivisors(i))
        if i%20 == 0 {
            fmt.Println()
        }
    }
}
Output:
The tau functions for the first 100 positive integers are:
 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  

GW-BASIC

10 FOR N = 1 TO 100
20 IF N < 3 THEN T=N: GOTO 70
30 T=2
40 FOR A = 2 TO INT( (N+1)/2 )
50 IF N MOD A = 0 THEN T = T + 1
60 NEXT A
70 PRINT T;
80 IF N MOD 10 = 0 THEN PRINT
90 NEXT N
Output:
 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

Haskell

tau :: Integral a => a -> a
tau n | n <= 0 = error "Not a positive integer"
tau n = go 0 (1, 1)
    where
    yo i = (i, i * i)
    go r (i, ii)
        | n < ii = r
        | n == ii = r + 1
        | 0 == mod n i = go (r + 2) (yo $ i + 1)
        | otherwise = go r (yo $ i + 1)

main = print $ map tau [1..100]
Output:
[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]

J

tau =: [:+/0=>:@i.|]
echo tau"0 [5 20$>:i.100
exit ''
Output:
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

Java

Translation of: D
public class TauFunction {
    private static long divisorCount(long n) {
        long total = 1;
        // Deal with powers of 2 first
        for (; (n & 1) == 0; n >>= 1) {
            ++total;
        }
        // Odd prime factors up to the square root
        for (long p = 3; p * p <= n; p += 2) {
            long count = 1;
            for (; n % p == 0; n /= p) {
                ++count;
            }
            total *= count;
        }
        // If n > 1 then it's prime
        if (n > 1) {
            total *= 2;
        }
        return total;
    }

    public static void main(String[] args) {
        final int limit = 100;
        System.out.printf("Count of divisors for the first %d positive integers:\n", limit);
        for (long n = 1; n <= limit; ++n) {
            System.out.printf("%3d", divisorCount(n));
            if (n % 20 == 0) {
                System.out.println();
            }
        }
    }
}
Output:
Count of divisors for the first 100 positive integers:
  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

jq

Works with: jq

Works with gojq, the Go implementation of jq

Preliminaries

See https://rosettacode.org/wiki/Sum_of_divisors#jq for the definition of `divisors` used here.

def count(s): reduce s as $x (0; .+1);

# For pretty-printing
def nwise($n):
  def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
  n;

def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;

The task

[range(1;101) | count(divisors)]
| nwise(10) | map(lpad(4)) | join("")
Output:
   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

Julia

Recycles code from http://www.rosettacode.org/wiki/Sequence:_smallest_number_greater_than_previous_term_with_exactly_n_divisors#Julia

using Primes

function numfactors(n)
    f = [one(n)]
    for (p, e) in factor(n)
        f = reduce(vcat, [f * p^j for j in 1:e], init = f)
    end
    length(f)
end

for i in 1:100
    print(rpad(numfactors(i), 3), i % 25 == 0 ? " \n" : " ")
end
Output:
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 

Lua

Translation of: Java
function divisorCount(n)
    local total = 1
    -- Deal with powers of 2 first
    while (n & 1) == 0 do
        total = total + 1
        n = math.floor(n / 2)
    end
    -- Odd prime factors up tot eh square root
    local p = 3
    while p * p <= n do
        local count = 1
        while n % p == 0 do
            count = count + 1
            n = n / p
        end
        total = total * count
        p = p + 2
    end
    -- If n > 1 then it's prime
    if n > 1 then
        total = total * 2
    end
    return total
end

limit = 100
print("Count of divisors for the first " .. limit .. " positive integers:")
for n=1,limit do
    io.write(string.format("%3d", divisorCount(n)))
    if n % 20 == 0 then
        print()
    end
end
Output:
Count of divisors for the first 100 positive integers:
  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

Mathematica/Wolfram Language

DivisorSum[#, 1 &] & /@ Range[100]
Output:
{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}

Modula-2

Translation of: C
MODULE TauFunc;
FROM InOut IMPORT WriteCard, WriteLn;

VAR i: CARDINAL;

PROCEDURE tau(n: CARDINAL): CARDINAL;
    VAR total, count, p: CARDINAL;
BEGIN
    total := 1;
    WHILE n MOD 2 = 0 DO
        n := n DIV 2;
        total := total + 1
    END;
    p := 3;
    WHILE p*p <= n DO
        count := 1;
        WHILE n MOD p = 0 DO
            n := n DIV p;
            count := count + 1
        END;
        total := total * count;
        p := p + 2
    END;
    IF n>1 THEN total := total * 2 END;
    RETURN total;
END tau;

BEGIN
    FOR i := 1 TO 100 DO
        WriteCard(tau(i), 3);
        IF i MOD 20 = 0 THEN WriteLn END
    END
END TauFunc.
Output:
  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

Nim

import math, strutils

func divcount(n: Natural): Natural =
  for i in 1..sqrt(n.toFloat).int:
    if n mod i == 0:
      inc result
      if n div i != i: inc result

echo "Count of divisors for the first 100 positive integers:"
for i in 1..100:
  stdout.write ($divcount(i)).align(3)
  if i mod 20 == 0: echo()
Output:
Count of divisors for the first 100 positive integers:
  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

PARI/GP

vector(100,X,numdiv(X))
Output:

[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]

Pascal

Works with: Extended Pascal
program tauFunction(output);

type
	{ name starts with `integer…` to facilitate sorting in documentation }
	integerPositive = 1..maxInt value 1;
	{ the `value …` will initialize all variables to this value }

{ returns Boolean value of the expression divisor ∣ dividend ----------- }
function divides(
		protected divisor: integerPositive;
		protected dividend: integer
	): Boolean;
begin
	{ in Pascal, function result variable has the same name as function }
	divides := dividend mod divisor = 0
end;

{ returns τ(i) --------------------------------------------------------- }
function tau(protected i: integerPositive): integerPositive;
var
	count, potentialDivisor: integerPositive;
begin
	{ count is initialized to 1 and every number is divisible by one }
	for potentialDivisor := 2 to i do
	begin
		count := count + ord(divides(potentialDivisor, i))
	end;
	
	{ in Pascal, there must be exactly one assignment to result variable }
	tau := count
end;

{ === MAIN ============================================================= }
var
	i: integerPositive;
	f: string(6);
begin
	for i := 1 to 100 do
	begin
		writeStr(f, 'τ(', i:1);
		writeLn(f:8, ') = ', tau(i):5)
	end
end.

Free Pascal

Works with: Free Pascal

and on TIO.RUN. Only test 0..99 for a nicer table.

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.
TIO.RUN:
The tau functions for the first 99 positive integers are:
    0  1  2  3  4  5  6  7  8  9 
 0| 1  1  2  2  3  2  4  2  4  3 
 1| 4  2  6  2  4  4  5  2  6  2 
 2| 6  4  4  2  8  3  4  4  6  2 
 3| 8  2  6  4  4  4  9  2  4  4 
 4| 8  2  8  2  6  6  4  2 10  3 
 5| 6  4  6  2  8  4  8  4  4  2 
 6|12  2  4  6  7  4  8  2  6  4 
 7| 8  2 12  2  4  6  6  4  8  2 
 8|10  5  4  2 12  4  4  4  8  2 
 9|12  4  6  4  4  4 12  2  6  6 

Perl

Library: ntheory
use strict;
use warnings;
use feature 'say';
use ntheory 'divisors';

my @x;
push @x, scalar divisors($_) for 1..100;

say "Tau function - first 100:\n" .
    ((sprintf "@{['%4d' x 100]}", @x[0..100-1]) =~ s/(.{80})/$1\n/gr);
Output:
   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

Phix

imperative

for i=1 to 100 do
    printf(1,"%3d",{length(factors(i,1))})
    if remainder(i,20)=0 then puts(1,"\n") end if
end for
Output:
  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

functional

same output

sequence r = apply(apply(true,factors,{tagset(100),{1}}),length)
puts(1,join_by(apply(true,sprintf,{{"%3d"},r}),1,20,""))

PL/I

Translation of: C
taufunc: procedure options(main);
    tau: procedure(nn) returns(fixed);
        declare (n, nn, tot, pf, cnt) fixed;
	tot = 1;
	do n=nn repeat(n/2) while(mod(n,2)=0);
            tot = tot + 1;
        end;
        do pf=3 repeat(pf+2) while(pf*pf<=n);
            do cnt=1 repeat(cnt+1) while(mod(n,pf)=0);
               n = n/pf;
            end;
            tot = tot * cnt;
        end;
        if n>1 then tot = tot * 2;
	return(tot);
    end tau;

    declare n fixed;
    do n=1 to 100;
        put edit(tau(n)) (F(3));
        if mod(n,20)=0 then put skip;
    end;
end taufunc;
Output:
  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


PL/M

Translation of: C
100H:

/* CP/M BDOS FUNCTIONS */
BDOS: PROCEDURE(F,A); DECLARE F BYTE, A ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; GO TO 0; END EXIT;
PR$CHAR: PROCEDURE(C); DECLARE C BYTE; CALL BDOS(2,C); END PR$CHAR; 
PR$STR: PROCEDURE(S); DECLARE S ADDRESS; CALL BDOS(9,S); END PR$STR;

/* PRINT BYTE IN A 3-CHAR COLUMN */
PRINT3: PROCEDURE(N);
    DECLARE (N, M) BYTE;
    M = 100;
    DO WHILE M>0;
        IF N>=M
            THEN CALL PR$CHAR('0' + (N/M) MOD 10);
            ELSE CALL PR$CHAR(' ');
        M = M/10;
    END;
END PRINT3;

/* TAU FUNCTION */
TAU: PROCEDURE(N) BYTE;
    DECLARE (N, TOTAL, COUNT, P) BYTE;
    TOTAL = 1;
    DO WHILE NOT N; 
        N = SHR(N,1);
        TOTAL = TOTAL + 1;
    END;
    P = 3;
    DO WHILE P*P <= N;
        COUNT = 1;
        DO WHILE N MOD P = 0;
            COUNT = COUNT + 1;
            N = N / P;
        END;
        TOTAL = TOTAL * COUNT;
        P = P + 2;
    END;
    IF N>1 THEN TOTAL = SHL(TOTAL, 1);
    RETURN TOTAL;
END TAU;

/* PRINT TAU 1..100 */
DECLARE N BYTE;
DO N=1 TO 100;
    CALL PRINT3(TAU(N));
    IF N MOD 20=0 THEN CALL PR$STR(.(13,10,'$'));
END;
CALL EXIT;
EOF
Output:
  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

PureBasic

If OpenConsole()
  For i=1 To 100
    If i<3 : Print(RSet(Str(i),4)) : Continue :EndIf
    c=2
    For j=2 To i/2+1 : c+Bool(i%j=0) : Next
    Print(RSet(Str(c),4))
    If i%10=0 : PrintN("") : EndIf
  Next
  Input()
EndIf
End
Output:
   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

Python

Using prime factorization

def factorize(n):
    assert(isinstance(n, int))
    if n < 0: 
        n = -n 
    if n < 2: 
        return 
    k = 0 
    while 0 == n%2: 
        k += 1 
        n //= 2 
    if 0 < k: 
        yield (2,k) 
    p = 3 
    while p*p <= n: 
        k = 0 
        while 0 == n%p: 
            k += 1 
            n //= p 
        if 0 < k: 
            yield (p,k)
        p += 2 
    if 1 < n: 
        yield (n,1) 

def tau(n): 
    assert(n != 0) 
    ans = 1 
    for (p,k) in factorize(n): 
        ans *= 1 + k
    return ans

if __name__ == "__main__":
    print([tau(n) for n in range(1,101)])

Finding divisors efficiently

def tau(n):
    assert(isinstance(n, int) and 0 < n)
    ans, i, j = 0, 1, 1
    while i*i <= n:
        if 0 == n%i:
            ans += 1
            j = n//i
            if j != i:
                ans += 1
        i += 1
    return ans

if __name__ == "__main__":
    print([tau(n) for n in range(1,101)])
Output:
[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]

Choosing the right abstraction

Yet another exercise in defining a divisors function.

'''The number of divisors of n'''

from itertools import count, islice
from math import floor, sqrt


# oeisA000005 :: [Int]
def oeisA000005():
    '''tau(n) (also called d(n) or sigma_0(n)),
       the number of divisors of n.
    '''
    return map(tau, count(1))


# tau :: Int -> Int
def tau(n):
    '''The number of divisors of n.
    '''
    return len(divisors(n))


# ------------------------- TEST -------------------------
# main :: IO ()
def main():
    '''The first 100 terms of OEIS A000005.
       (Shown in rows of 10)
    '''
    terms = take(100)(
        oeisA000005()
    )
    columnWidth = 1 + len(str(max(terms)))

    print(
        '\n'.join(
            ''.join(
                str(term).rjust(columnWidth)
                for term in row
            )
            for row in chunksOf(10)(terms)
        )
    )


# ----------------------- GENERIC ------------------------

# chunksOf :: Int -> [a] -> [[a]]
def chunksOf(n):
    '''A series of lists of length n, subdividing the
       contents of xs. Where the length of xs is not evenly
       divible, the final list will be shorter than n.
    '''
    def go(xs):
        return [
            xs[i:n + i] for i in range(0, len(xs), n)
        ] if 0 < n else None
    return go


# divisors :: Int -> [Int]
def divisors(n):
    '''List of all divisors of n including n itself.
    '''
    root = floor(sqrt(n))
    lows = [x for x in range(1, 1 + root) if 0 == n % x]
    return lows + [n // x for x in reversed(lows)][
        (1 if n == (root * root) else 0):
    ]


# take :: Int -> [a] -> [a]
# take :: Int -> String -> String
def take(n):
    '''The prefix of xs of length n,
       or xs itself if n > length xs.
    '''
    def go(xs):
        return (
            xs[0:n]
            if isinstance(xs, (list, tuple))
            else list(islice(xs, n))
        )
    return go


# MAIN ---
if __name__ == '__main__':
    main()
Output:
  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

Quackery

factors is defined at Factors of an integer#Quackery.


  [ factors size ] is tau ( n --> n )

  [] [] 
  100 times [ i^ 1+ tau join ]
  witheach [ number$ nested join ]
  70 wrap$
Output:
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

R

This only takes one line.

lengths(sapply(1:100, function(n) c(Filter(function(x) n %% x == 0, seq_len(n %/% 2)), n)))

Raku

Yet more tasks that are tiny variations of each other. Tau function, Tau number, Sum of divisors and Product of divisors all use code with minimal changes. What the heck, post 'em all.

use Prime::Factor:ver<0.3.0+>;
use Lingua::EN::Numbers;

say "\nTau function - first 100:\n",        # ID
(1..*).map({ +.&divisors })[^100]\          # the task
.batch(20)».fmt("%3d").join("\n");          # display formatting

say "\nTau numbers - first 100:\n",         # ID
(1..*).grep({ $_ %% +.&divisors })[^100]\   # the task
.batch(10)».&comma».fmt("%5s").join("\n");  # display formatting

say "\nDivisor sums - first 100:\n",        # ID
(1..*).map({ [+] .&divisors })[^100]\       # the task
.batch(20)».fmt("%4d").join("\n");          # display formatting

say "\nDivisor products - first 100:\n",    # ID
(1..*).map({ [×] .&divisors })[^100]\       # the task
.batch(5)».&comma».fmt("%16s").join("\n");  # display formatting
Output:
Tau function - first 100:
  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

Tau numbers - first 100:
    1     2     8     9    12    18    24    36    40    56
   60    72    80    84    88    96   104   108   128   132
  136   152   156   180   184   204   225   228   232   240
  248   252   276   288   296   328   344   348   360   372
  376   384   396   424   441   444   448   450   468   472
  480   488   492   504   516   536   560   564   568   584
  600   612   625   632   636   640   664   672   684   708
  712   720   732   776   792   804   808   824   828   852
  856   864   872   876   880   882   896   904   936   948
  972   996 1,016 1,040 1,044 1,048 1,056 1,068 1,089 1,096

Divisor sums - first 100:
   1    3    4    7    6   12    8   15   13   18   12   28   14   24   24   31   18   39   20   42
  32   36   24   60   31   42   40   56   30   72   32   63   48   54   48   91   38   60   56   90
  42   96   44   84   78   72   48  124   57   93   72   98   54  120   72  120   80   90   60  168
  62   96  104  127   84  144   68  126   96  144   72  195   74  114  124  140   96  168   80  186
 121  126   84  224  108  132  120  180   90  234  112  168  128  144  120  252   98  171  156  217

Divisor products - first 100:
               1                2                3                8                5
              36                7               64               27              100
              11            1,728               13              196              225
           1,024               17            5,832               19            8,000
             441              484               23          331,776              125
             676              729           21,952               29          810,000
              31           32,768            1,089            1,156            1,225
      10,077,696               37            1,444            1,521        2,560,000
              41        3,111,696               43           85,184           91,125
           2,116               47      254,803,968              343          125,000
           2,601          140,608               53        8,503,056            3,025
       9,834,496            3,249            3,364               59   46,656,000,000
              61            3,844          250,047        2,097,152            4,225
      18,974,736               67          314,432            4,761       24,010,000
              71  139,314,069,504               73            5,476          421,875
         438,976            5,929       37,015,056               79    3,276,800,000
          59,049            6,724               83  351,298,031,616            7,225
           7,396            7,569       59,969,536               89  531,441,000,000
           8,281          778,688            8,649            8,836            9,025
 782,757,789,696               97          941,192          970,299    1,000,000,000

REXX

/*REXX program counts the number of divisors (tau,  or sigma_0)  up to and including  N.*/
parse arg LO HI cols .                           /*obtain optional argument from the CL.*/
if   LO=='' |   LO==","  then  LO=   1           /*Not specified?  Then use the default.*/
if   HI=='' |   HI==","  then  HI=  LO + 100 - 1 /*Not specified?  Then use the default.*/
if cols=='' | cols==","  then cols= 20           /* "      "         "   "   "     "    */
w= 2 + (HI>45359)                                /*W:  used to align the output columns.*/
say 'The number of divisors  (tau)  for integers up to '    n    " (inclusive):";      say
say '─index─'   center(" tau (number of divisors) ",  cols * (w+1)  +  1,  '─')
$=;                                   c= 0       /*$:  the output list,  shown ROW/line.*/
                do j=LO  to HI;       c= c + 1   /*list # proper divisors (tau) 1 ──► N */
                $= $  right( tau(j), w)          /*add a tau number to the output list. */
                if c//cols \== 0  then iterate   /*Not a multiple of ROW? Don't display.*/
                idx= j - cols + 1                /*calculate index value (for this row).*/
                say center(idx, 7)    $;  $=     /*display partial list to the terminal.*/
                end   /*j*/

if $\==''  then say center(idx+cols, 7)    $     /*there any residuals left to display ?*/
exit 0                                           /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
tau: procedure; parse arg x 1 y                  /*X  and  $  are both set from the arg.*/
     if x<6  then return 2 + (x==4) - (x==1)     /*some low #s should be handled special*/
     odd= x // 2                                 /*check if  X  is odd (remainder of 1).*/
     if odd  then       #= 2                     /*Odd?    Assume divisor count of  2.  */
             else do;   #= 4;   y= x % 2;   end  /*Even?      "      "      "    "  4.  */
                                                 /* [↑]  start with known number of divs*/
        do j=3  for x%2-3  by 1+odd  while j<y   /*for odd number,  skip even numbers.  */
        if x//j==0  then do                      /*if no remainder, then found a divisor*/
                         #= # + 2;   y= x % j    /*bump # of divisors;  calculate limit.*/
                         if j>=y  then do;   #= # - 1;   leave;   end   /*reached limit?*/
                         end                     /*                     ___             */
                    else if j*j>x  then leave    /*only divide up to   √ x              */
        end   /*j*/;               return #      /* [↑]  this form of DO loop is faster.*/
output   when using the default input:
The number of divisors  (tau)  for integers up to  100  (inclusive):

─index─ ──────────────────────────── tau (number of divisors) ────────────────────────────
   1       1   2   2   3   2   4   2   4   3   4   2   6   2   4   4   5   2   6   2   6
  21       4   4   2   8   3   4   4   6   2   8   2   6   4   4   4   9   2   4   4   8
  41       2   8   2   6   6   4   2  10   3   6   4   6   2   8   4   8   4   4   2  12
  61       2   4   6   7   4   8   2   6   4   8   2  12   2   4   6   6   4   8   2  10
  81       5   4   2  12   4   4   4   8   2  12   4   6   4   4   4  12   2   6   6   9

Ring

see "The tau functions for the first 100 positive integers are:" + nl 

n = 0
num = 0
limit = 100
while num < limit
      n = n + 1
      tau = 0
      for m = 1 to n
          if n%m = 0
             tau = tau + 1
          ok
      next
      num = num + 1
      if num%10 = 1
         see nl
      ok
      tau = string(tau)
      if len(tau) = 1
         tau = " " + tau 
      ok
      see "" + tau + " "
end

Output:

The tau functions for the first 100 positive integers are:

 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 

Ruby

require 'prime'

def tau(n) = n.prime_division.inject(1){|res, (d, exp)| res *= exp + 1}

(1..100).map{|n| tau(n).to_s.rjust(3) }.each_slice(20){|ar| puts ar.join}
Output:
  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

Rust

// returns the highest power of i that is a factor of n,
// and n divided by that power of i
fn factor_exponent(n: i32, i: i32) -> (i32, i32) {
	if n % i == 0 {
		let (a, b) = factor_exponent(n / i, i);
		(a + 1, b)
	} else {
		(0, n)
	}
}

fn tau(n: i32) -> i32 {
	for i in 2..(n+1) {
		if n % i == 0 {
			let (count, next) = factor_exponent(n, i);
			return (count + 1) * tau(next);
		}
	}
	return 1;
}

fn main() {
	for i in 1..101 {
		print!("{} ", tau(i));
	}
}

Output:

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

Sidef

Built-in:

say { .sigma0 }.map(1..100).join(' ')
Output:
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

Swift

import Foundation

// See https://en.wikipedia.org/wiki/Divisor_function
func divisorCount(number: Int) -> Int {
    var n = number
    var total = 1
    // Deal with powers of 2 first
    while (n & 1) == 0 {
        total += 1
        n >>= 1
    }
    // Odd prime factors up to the square root
    var p = 3
    while p * p <= n {
        var count = 1
        while n % p == 0 {
            count += 1
            n /= p
        }
        total *= count
        p += 2
    }
    // If n > 1 then it's prime
    if n > 1 {
        total *= 2
    }
    return total
}

let limit = 100
print("Count of divisors for the first \(limit) positive integers:")
for n in 1...limit {
    print(String(format: "%3d", divisorCount(number: n)), terminator: "")
    if n % 20 == 0 {
        print()
    }
}
Output:
Count of divisors for the first 100 positive integers:
  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

Tiny BASIC

    LET N = 0
 10 LET N = N + 1
    IF N < 3 THEN GOTO 100
    LET T = 2
    LET A = 1
 20 LET A = A + 1
    IF (N/A)*A = N THEN LET T = T + 1
    IF A<(N+1)/2 THEN GOTO 20
 30 PRINT "Tau(",N,") = ",T
    IF N<100 THEN GOTO 10
    END
100 LET T = N
    GOTO 30


Verilog

module main;
  integer N, T, A;
  
  initial begin
    $display("The tau functions for the first 100 positive integers are:\n");
    for (N = 1; N <= 100; N=N+1) begin
        if (N < 3) T = N;
        else begin
            T = 2;
            for (A = 2; A <= (N+1)/2; A=A+1) begin
                if (N % A == 0) T = T + 1;
            end
        end
        
        $write(T);
        if (N % 10 == 0) $display("");
    end
      $finish ;
  end
endmodule

Wren

Library: Wren-math
Library: Wren-fmt
import "/math" for Int
import "/fmt" for Fmt

System.print("The tau functions for the first 100 positive integers are:")
for (i in 1..100) {
    Fmt.write("$2d  ", Int.divisors(i).count)
    if (i % 20 == 0) System.print()
}
Output:
The tau functions for the first 100 positive integers are:
 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 

XPL0

int N, D, C;
[Format(3, 0);
for N:= 1 to 100 do
    [C:= 0;
    for D:= 1 to N do
        if rem(N/D) = 0 then C:= C+1;
    RlOut(0, float(C));
    if rem(N/20) = 0 then CrLf(0);
    ];
]
Output:
  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