Movatterモバイル変換


[0]ホーム

URL:


Jump to content
Rosetta Code
Search

Tau number

From Rosetta Code
Task
Tau number
You are encouraged tosolve this task according to the task description, using any language you may know.

ATau number is a positive integer divisible by the count of its positive divisors.


Task

Show the first  100   Tau numbers.The numbers shall begenerated during run-time (i.e. the code may not contain string literals, sets/arrays of integers, or alike).


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 ansF is_tau_number(n)   I n <= 0      R 0B   R 0 == n % tau(n)V n = 1[Int] ansL ans.len < 100   I is_tau_number(n)      ans.append(n)   n++print(ans)
Output:
[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, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096]

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  FIRETURN (result)PROC Main()  CARD n=[1],max=[100],count=[0],divCount  WHILE count<max  DO    divCount=DivisorCount(n)    IF n MOD divCount=0 THEN      PrintC(n) Put(32)      count==+1    FI    n==+1  ODRETURN
Output:

Screenshot from Atari 8-bit computer

1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132 136 152 156 180 184204 225 228 232 240 248 252 276 288 296 328 344 348 360 372 376 384 396 424 441444 448 450 468 472 480 488 492 504 516 536 560 564 568 584 600 612 625 632 636640 664 672 684 708 712 720 732 776 792 804 808 824 828 852 856 864 872 876 880882 896 904 936 948 972 996 1016 1040 1044 1048 1056 1068 1089 1096

Agena

Using Agena's standard numtheory.ifactors for factorisation, as in theTau function task.

scope # find some Tau numbers - numbers divisible by the count of their divisors    # returns the number of divisors of v    local proc divisor_count( v :: number ) :: number        # numtheory.ifactors will return something like (e.g., for 24): [1, [[2, 3], [3, 1]]]        local total := 1;        if v > 1 then            local constant factors := numtheory.ifactors( v );            for f to size factors[ 2 ] do                total *:= factors[ 2, f, 2 ] + 1            od        fi;        return total    end;    scope        local constant limit := 100;        local count          := 0;        printf( "The first %d tau numbers:\n", limit );        for n while count < limit do            local constant dc := divisor_count( n );            if n mod dc = 0 then                printf( "%5d", n );                count +:= 1;                if count mod 10 = 0 then print() else printf( " " ) fi            fi        od    endend
Output:
The first 100 tau numbers:     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  1016  1040  1044  1048  1056  1068  1089  1096

ALGOL 60

begincomment - return n mod m;integer procedure mod(n, m);  value n, m; integer n, m;begin  mod := n - entier(n / m) * m;end;comment - return the Tau (number of divisors) of n;integer procedure tau(n);  value n; integer n;begin  integer i, t, limit;  if n < 3 then     t := n  else     begin       t := 2;       limit := (n + 1) / 2;       for i := 2 step 1 until limit do          begin             if mod(n, i) = 0 then t := t + 1;          end;     end;  tau := t;end;comment - output n to screen in field of width w;procedure outdec(n, w);  value n, w; integer n, w;begin  integer m;  m := 10 ** (w-1);  for m := m, m/10 while n < m do    begin      outstring(1," ");    end;  outinteger(1,n);end;integer i, found;outstring(1,"First 100 Tau numbers:\n");found := 0;for i := 1, i+1 while found < 100 do  begin    if mod(i,tau(i)) = 0 then      begin        outdec(i,5);        found := found + 1;        if mod(found,10) = 0 then outstring(1,"\n");      end;  end;end
Output:
First 100 Tau numbers:     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   1016   1040   1044   1048   1056   1068   1089   1096


ALGOL 68

Translation of:C++
BEGIN # find tau numbers - numbers divisible by the count of their divisors  #    # 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 #            INT p := 1;            WHILE  p +:= 2;                   ( 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 tau limit  = 100;        INT tau count := 0;        print( ( "The first ", whole( tau limit, 0 ), " tau numbers:", newline ) );        FOR n WHILE tau count < tau limit DO            IF n MOD divisor count( n ) = 0 THEN                tau count +:= 1;                print( ( whole( n, -6 ) ) );                IF tau count MOD 10 = 0 THEN print( ( newline ) ) FI            FI        OD    ENDEND
Output:
The first 100 tau numbers:     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  1016  1040  1044  1048  1056  1068  1089  1096

ALGOL-M

begininteger array dcount[1:1100];integer i, j, n;integer function mod(a,b);integer a,b;mod := a-a/b*b;% Calculate counts of divisors for 1 .. 1100 %for i := 1 step 1 until 1100 do dcount[i] := 1;for i := 2 step 1 until 1100 dobegin    j := i;    while j <= 1100 do    begin        dcount[j] := dcount[j] + 1;        j := j + i;    end;end;n := 0;i := 1;while n < 100 dobegin    if mod(i, dcount[i])=0 then    begin        if mod(n, 10)=0            then write(i)            else writeon(i);        n := n + 1;    end;    i := i + 1;end;end
Output:
     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  1016  1040  1044  1048  1056  1068  1089  1096

ALGOL W

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

Same as Algol 68.

APL

Works with:Dyalog APL
((/⍨)(0=(0+.=⍳|⊢)|⊢)¨)1096
Output:
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 1016 1040 1044 1048 1056 1068 1089 1096

AppleScript

onfactorCount(n)if(n<1)thenreturn0setcounterto2setsqrtton^0.5if(sqrtmod1=0)thensetcounterto1repeatwithifrom(sqrtdiv1)to2by-1if(nmodi=0)thensetcountertocounter+2endrepeatreturncounterendfactorCount-- Task code:localoutput,n,counter,astidsetoutputto{"First 100 tau numbers:"}setnto0setcounterto0repeatuntil(counter=100)setnton+1if(nmod(factorCount(n))=0)thensetcountertocounter+1if(countermod20=1)thensetendofoutputtolinefeedsetendofoutputtotext-5thru-1of("    "&n)endifendrepeatsetastidtoAppleScript'stext item delimiterssetAppleScript'stext item delimitersto""setoutputtooutputastextsetAppleScript'stext item delimiterstoastidreturnoutput
Output:
"First 100 tau numbers:    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 1016 1040 1044 1048 1056 1068 1089 1096"

Arturo

tauFun:function[x]->sizefactorsxfound:0i:1while[found<100][if0=i%tauFuni[printspadto:stringi5found:found+1if0=found%10->print""]i:i+1]
Output:
    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 1016 1040 1044 1048 1056 1068 1089 1096

Asymptote

intn=0;intnum=0;intlimit=100;write("The first $limit tau numbers are:");do{++n;inttau=0;for(intm=1;m<=n;++m){if(n%m==0)++tau;}if(n%tau==0){++num;write(format("%5d",n),suffix=none);}}while(num<limit);

AutoHotkey

n:=c:=0while(c<100)ifisTau(++n)c++,result.=SubStr("   "n,-3).(Mod(c,10)?" ":"`n")MsgBox%resultreturnisTau(num){return(num/(n:=StrSplit(Factors(num),",").Count())=floor(num/n))}Factors(n){Loop,%floor(sqrt(n))v:=A_Index=1?1","n:mod(n,A_Index)?v:v","A_Index","n//A_IndexSort,v,NUD,Return,v}
Output:
   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 1016 1040 1044 1048 1056 1068 1089 1096

AWK

# syntax: GAWK -f TAU_NUMBER.AWKBEGIN{print("The first 100 tau numbers:")while(count<100){i++if(i%count_divisors(i)==0){printf("%4d ",i)if(++count%10==0){printf("\n")}}}exit(0)}functioncount_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 first 100 tau numbers:   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 1016 1040 1044 1048 1056 1068 1089 1096

BASIC

10DEFINTA-Z20S=0:N=130C=140IFN<>1THENFORI=1TON/2:C=C-(NMODI=0):NEXT50IFNMODC=0THENPRINTN,:S=S+160N=N+170IFS<100THEN3080END
Output:
 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           1016          1040          1044 1048          1056          1068          1089          1096

ANSI BASIC

Translation of:ALGOL 60
Works with:Decimal BASIC
100REM Tau number110DECLAREEXTERNALFUNCTIONTau120PRINT"First 100 Tau numbers:"130LETC=0140LETI=1150DOWHILEC<100160IFMOD(I,Tau(I))=0THEN170PRINTUSING"#####":I;180LETC=C+1190IFMOD(C,10)=0THENPRINT200ENDIF210LETI=I+1220LOOP230END240!250REM Return the Tau (number of divisors) of N260EXTERNALFUNCTIONTau(N)270IFN<3THEN280LETT=N290ELSE300LETT=2310FORI=2TOINT((N+1)/2)320IFMOD(N,I)=0THENLETT=T+1330NEXTI340ENDIF350LETTau=T360ENDFUNCTION
Output:
First 100 Tau numbers:    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 1016 1040 1044 1048 1056 1068 1089 1096

Applesoft BASIC

Translation of:MSX Basic
100HOME110PRINT"The first 100 tau numbers are:"120N=0130NUM=0140LIMIT=100150IFNUM>=LIMITTHENGOTO230160N=N+1170TAU=0180FORM=1TON190IFN-INT(N/M)*M=0THENTAU=TAU+1200NEXTM210IFN-INT(N/TAU)*TAU=0THENNUM=NUM+1:PRINTN;" ";220GOTO150230END

BASIC256

print "The first 100 tau numbers are:"n = 0num = 0limit = 100while num < limitn += 1tau = 0for m = 1 to nif n mod m = 0 then tau += 1next mif n mod tau = 0 thennum += 1if num mod 10 = 1 then printprint rjust(string(n), 6);end ifend whileend

Chipmunk Basic

Translation of:BASIC256
Works with:Chipmunk Basic version 3.6.4
100cls110print"The first 100 tau numbers are:"120n=0130num=0140limit=100150whilenum<limit160n=n+1170tau=0180form=1ton190ifnmodm=0thentau=tau+1200nextm210ifnmodtau=0then220num=num+1230ifnummod10=1thenprint240printn,250endif260wend270print280end

Gambas

Translation of:FreeBASIC
PublicSubMain()DimcAsInteger=0,iAsInteger=1Print"The first 100 tau numbers are:\n"Whilec<100IfisTau(i)ThenPrintFormat$(i,"######");c+=1IfcMod10=0ThenPrintEndIfi+=1WendEndFunctionnumdiv(nAsInteger)AsIntegerDimcAsInteger=2ForiAsInteger=2To(n+1)\2IfnModi=0Thenc+=1NextReturncEndFunctionFunctionisTau(nAsInteger)AsBooleanIfn=1ThenReturnTrueReturnIIf(nModnumdiv(n)=0,True,False)EndFunction

GW-BASIC

Works with:PC-BASIC version any
Translation of:Chipmunk Basic
100CLS110PRINT"The first 100 tau numbers are:"120N=0130NUM=0140LIMIT=100150WHILENUM<LIMIT160N=N+1170TAU=0180FORM=1TON190IFNMODM=0THENTAU=TAU+1200NEXTM210IFNMODTAU=0THENNUM=NUM+1:PRINTN;"  ";220WEND230END

IS-BASIC

100 PROGRAM "TauNr.bas"110 LET LIMIT=100120 LET N,NUM=0130 PRINT "The first";LIMIT;"tau numbers are:"140 DO WHILE NUM<LIMIT150   LET N=N+1160   LET TAU=0170   FOR M=1 TO N180     IF MOD(N,M)=0 THEN LET TAU=TAU+1190   NEXT 200   IF MOD(N,TAU)=0 THEN LET NUM=NUM+1:PRINT N,210 LOOP

Minimal BASIC

10PRINT"THE FIRST 100 TAU NUMBERS ARE:"20LETN=030LETM=040LETL=10050IFM>=LTHEN19060LETN=N+170LETT=080FORI=1TON90IFN-INT(N/I)*I=0THEN110100GOTO120110LETT=T+1120NEXTI130IFN-INT(N/T)*T=0THEN160140GOTO50150STOP160LETM=M+1170PRINTN;180GOTO140190END

MSX Basic

Works with:MSX BASIC version any
Translation of:Chipmunk Basic
100CLS110PRINT"The first 100 tau numbers are:"120N=0130NUM=0140LIMIT=100150IFNUM>LIMITTHENGOTO230160N=N+1170TAU=0180FORM=1TON190IFNMODM=0THENTAU=TAU+1200NEXTM210IFNMODTAU=0THENNUM=NUM+1:PRINTN;220GOTO150230END

OxygenBasic

Translation of:FreeBASIC
function numdiv (n as integer) as integer    dim as integer c = 0, k    for k = 1 to n        if n mod k = 0 then c += 1    next k    return cend functionfunction isTau (n as integer) as boolean    return (n mod numdiv(n) = 0)end functiondim as integer c = 0, i = 1printl "The first 100 tau numbers are:" crwhile c < 100    if isTau(i) then        print i, "  ";        c += 1        if c mod 10 = 0 then printl    end if    i += 1wendprintl cr "Enter ..."waitkey

QBasic

Works with:QBasic version 1.1
PRINT"The first 100 tau numbers are:"n=0num=0limit=100DOn=n+1tau=0FORm=1TOnIFnMODm=0THENtau=tau+1NEXTmIFnMODtau=0THENnum=num+1IFnumMOD10=1THENPRINTPRINTUSING" ####";n;'""; n; " ";ENDIFLOOPWHILEnum<limitEND

QB64

DimAs_UnsignedIntegerc,ic=0:i=1Print"The first 100 tau numbers are:"PrintWhilec<100IfisTau(i)ThenPrintUsing("######");i;c=c+1IfcMod10=0ThenPrintEndIfi=i+1WendEndFunctionnumdiv(nAs_UnsignedInteger)DimAs_UnsignedIntegerc,kc=0Fork=1TonIfnModk=0Thenc=c+1Nextknumdiv=cEndFunctionFunctionisTau(nAsInteger)IfnModnumdiv(n)=0ThenisTau=-1ElseisTau=0EndFunction
Output:
Same as FreeBASIC entry.

Run BASIC

Works with:Just BASIC
Works with:Liberty BASIC
print"The first 100 tau numbers are:"n=0num=0limit=100whilenum<limitn=n+1tau=0form=1tonifnmodm=0thentau=tau+1nextmifnmodtau=0thennum=num+1ifnummod10=1thenprintprintusing("######",n);endifwendend

True BASIC

LETn=0LETnum=0LETlimit=100DOLETn=n+1LETtau=0FORm=1TOnIFREMAINDER(n,m)=0THENLETtau=tau+1NEXTmIFREMAINDER(n,tau)=0THENLETnum=num+1IFREMAINDER(num,10)=1THENPRINTPRINT"";n;" ";ENDIFLOOPWHILEnum<limitEND

Tiny BASIC

REM Rosetta Code problem: https://rosettacode.org/wiki/Tau_numberREM by Jjuanhdez, 11/2023REMTaunumberLETC=0LETN=0LETX=100LETT=010LETC=C+1LETT=0LETM=120IFC-(C/M)*M<>0THENGOTO30LETT=T+130LETM=M+1IFM<C+1THENGOTO20IFC-(C/T)*T<>0THENGOTO40LETN=N+1PRINTC40IFN<XTHENGOTO10END

XBasic

Translation of:BASIC256
Works with:Windows XBasic
PROGRAM"Tau number"VERSION"0.0000"DECLAREFUNCTIONEntry()FUNCTIONEntry()PRINT"The first 100 tau numbers are:"n=0num=0limit=100DOWHILEnum<limitINCntau=0FORm=1TOnIFnMODm=0THENINCtauNEXTmIFnMODtau=0THENINCnumIFnumMOD10=1THENPRINTPRINTFORMAT$("######",n);ENDIFLOOPENDFUNCTIONENDPROGRAM

Yabasic

print "The first 100 tau numbers are:"n = 0num = 0limit = 100while num < limit      n = n + 1      tau = 0      for m = 1 to n          if mod(n, m) = 0 then tau = tau + 1 : fi      next m      if mod(n, tau) = 0 then         num = num + 1         if mod(num, 10) = 1 then print : fi         print n using "####";      end ifwendprintend

BCPL

get "libhdr"// Count the divisors of 1..Nlet divcounts(v, n) be$(  // Every positive number is divisible by 1    for i=1 to n do v!i := 1;    for i=2 to n do     $(  let j = i        while j <= n do        $(  // J is divisible by I            v!j := v!j + 1            j := j + i        $)    $)$)// Given a stored vector of divisors counts, is a number a tau number?let tau(v, i) = i rem v!i = 0    let start() be$(  let dvec = vec 1100    let n, seen = 1, 0        divcounts(dvec, 1100) // find amount of divisors for each number    while seen < 100 do    $(  if tau(dvec, n) then        $(  writed(n, 5)            seen := seen + 1            if seen rem 10 = 0 then wrch('*N')        $)        n := n + 1    $)$)
Output:
    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 1016 1040 1044 1048 1056 1068 1089 1096

BQN

# 1 if number is a tau numberIs_tau0=(+´0=(1+↕)|)|# recursively find 100 tau numbers0{100≤≠𝕩?𝕩;Is_tau𝕨?(𝕨+1)𝕊(𝕩𝕨);(𝕨+1)𝕊𝕩}⟨⟩
Output:
⟨ 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 1016 1040 1044 1048 1056 1068 1089 1096 ⟩

If it is already known that the 100th number is 1096, this code can be used instead for the same output.

(0=(+´0=(1+↕)|)|)¨/↕1097

C

Translation of:C++
#include<stdio.h>unsignedintdivisor_count(unsignedintn){unsignedinttotal=1;unsignedintp;// Deal with powers of 2 firstfor(;(n&1)==0;n>>=1){++total;}// Odd prime factors up to the square rootfor(p=3;p*p<=n;p+=2){unsignedintcount=1;for(;n%p==0;n/=p){++count;}total*=count;}// If n > 1 then it's primeif(n>1){total*=2;}returntotal;}intmain(){constunsignedintlimit=100;unsignedintcount=0;unsignedintn;printf("The first %d tau numbers are:\n",limit);for(n=1;count<limit;++n){if(n%divisor_count(n)==0){printf("%6d",n);++count;if(count%10==0){printf("\n");}}}return0;}
Output:
The first 100 tau numbers are:     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  1016  1040  1044  1048  1056  1068  1089  1096

C++

#include<iomanip>#include<iostream>// See https://en.wikipedia.org/wiki/Divisor_functionunsignedintdivisor_count(unsignedintn){unsignedinttotal=1;// Deal with powers of 2 firstfor(;(n&1)==0;n>>=1)++total;// Odd prime factors up to the square rootfor(unsignedintp=3;p*p<=n;p+=2){unsignedintcount=1;for(;n%p==0;n/=p)++count;total*=count;}// If n > 1 then it's primeif(n>1)total*=2;returntotal;}intmain(){constunsignedintlimit=100;std::cout<<"The first "<<limit<<" tau numbers are:\n";unsignedintcount=0;for(unsignedintn=1;count<limit;++n){if(n%divisor_count(n)==0){std::cout<<std::setw(6)<<n;++count;if(count%10==0)std::cout<<'\n';}}}
Output:
The first 100 tau numbers are:     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  1016  1040  1044  1048  1056  1068  1089  1096

C#

internalclassProgram{privatestaticvoidMain(string[]args){longlimit=100;Console.WriteLine($"The first {limit} tau numbers are:");longcount=0;for(longn=1;count<limit;++n){if(IsTauNumber(n)){Console.Write($"{n, 6} ");++count;if(count%10==0){Console.WriteLine();}}}}privatestaticboolIsTauNumber(longn){returnn%DivisorCount(n)==0;}privatestaticlongDivisorCount(longn){longtotal=1;// Deal with powers of 2 firstfor(;(n&1)==0;n>>=1){++total;}// Odd prime factors up to the square rootfor(longp=3;p*p<=n;p+=2){longcount=1;for(;n%p==0;n/=p){++count;}total*=count;}// If n > 1 then it's primeif(n>1){total*=2;}returntotal;}}
Output:
The first 100 tau numbers are:     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   1016   1040   1044   1048   1056   1068   1089   1096

Clojure

Translation of:Raku
(require'[clojure.string:refer[join]])(require'[clojure.pprint:refer[cl-format]])(defndivisors[n](filter#(zero?(remn%))(range1(incn))))(defndisplay-results[labelper-linewidthnums](doall(map println(cons(str"\n"label":")(list(join"\n"(map#(join" "%)(partition-allper-line(map#(cl-formatnil"~v:d"width%)nums)))))))))(display-results"Tau function - first 100"203(take100(map(comp countdivisors)(drop1(range)))))(display-results"Tau numbers – first 100"105(take100(filter#(zero?(rem%(count(divisors%))))(drop1(range)))))(display-results"Divisor sums – first 100"204(take100(map#(reduce +(divisors%))(drop1(range)))))(display-results"Divisor products – first 100"516(take100(map#(reduce *(divisors%))(drop1(range)))))
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   9Tau 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,096Divisor 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  217Divisor 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

CLU

% Count the divisors of [1..N]count_divisors = proc (n: int) returns (sequence[int])    divs: array[int] := array[int]$fill(1, n, 1)    for i: int in int$from_to(2, n) do        for j: int in int$from_to_by(i, n, i) do            divs[j] := divs[j] + 1        end    end    return(sequence[int]$a2s(divs))end count_divisors% Find Tau numbers up to a given limittau_numbers = iter (lim: int) yields (int)    divs: sequence[int] := count_divisors(lim)    n: int := 0    while n < lim do        n := n + 1        if n // divs[n] = 0 then yield(n) end    endend tau_numbers% Show the first 100 Tau numbersstart_up = proc ()    po: stream := stream$primary_output()    seen: int := 0        for n: int in tau_numbers(1100) do        seen := seen + 1        stream$putright(po, int$unparse(n), 5)        if seen // 10 = 0 then stream$putl(po, "") end        if seen >= 100 then break end    endend start_up
Output:
    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 1016 1040 1044 1048 1056 1068 1089 1096

Cowgol

include "cowgol.coh";# <nowiki>Numbered list item</nowiki># Get count of positive divisors of numbersub pos_div(num: uint16): (count: uint16) is    count := 1;    if num != 1 then        var cur: uint16 := 1;        while cur <= num/2 loop            if num % cur == 0 then                count := count + 1;            end if;            cur := cur + 1;        end loop;    end if;end sub;# Print first 100 Tau numbersvar nums: uint8 := 0;var cur: uint16 := 0;var col: uint16 := 10;while nums < 100 loop    cur := cur + 1;    if cur % pos_div(cur) == 0 then        print_i16(cur);        col := col - 1;        if col == 0 then            print_nl();            col := 10;        else            print_char('\t');        end if;        nums := nums + 1;    end if;end loop;
Output:
1       2       8       9       12      18      24      36      40      5660      72      80      84      88      96      104     108     128     132136     152     156     180     184     204     225     228     232     240248     252     276     288     296     328     344     348     360     372376     384     396     424     441     444     448     450     468     472480     488     492     504     516     536     560     564     568     584600     612     625     632     636     640     664     672     684     708712     720     732     776     792     804     808     824     828     852856     864     872     876     880     882     896     904     936     948972     996     1016    1040    1044    1048    1056    1068    1089    1096

Craft Basic

definecount=0,num=0,mod=0definenums=100,tau=0doletcount=count+1lettau=0letmod=1doifcount%mod=0thenlettau=tau+1endifletmod=mod+1loopmod<count+1ifcount%tau=0thenletnum=num+1printcountendifloopnum<nums
Output:
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 1016 1040 1044 1048 1056 1068 1089 1096

D

Translation of:C++
importstd.stdio;uintdivisor_count(uintn){uinttotal=1;// Deal with powers of 2 firstfor(;(n&1)==0;n>>=1){++total;}// Odd prime factors up to the square rootfor(uintp=3;p*p<=n;p+=2){uintcount=1;for(;n%p==0;n/=p){++count;}total*=count;}// If n > 1 then it's primeif(n>1){total*=2;}returntotal;}voidmain(){immutablelimit=100;writeln("The first ",limit," tau numbers are:");uintcount=0;for(uintn=1;count<limit;++n){if(n%divisor_count(n)==0){writef("%6d",n);++count;if(count%10==0){writeln;}}}}
Output:
The first 100 tau numbers are:     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  1016  1040  1044  1048  1056  1068  1089  1096

Dart

Translation of:C++
intdivisorCount(intn){inttotal=1;// Deal with powers of 2 firstfor(;(n&1)==0;n>>=1)total++;// Odd prime factors up to the square rootfor(intp=3;p*p<=n;p+=2){intcount=1;for(;n%p==0;n~/=p)count++;total*=count;}// If n > 1 then it's primeif(n>1)total*=2;returntotal;}voidmain(){constintlimit=100;print("The first$limit tau numbers are:");intcount=0;for(intn=1;count<limit;n++){if(n%divisorCount(n)==0){print(n.toString().padLeft(6));count++;}}}

Delphi

Library: System.SysUtils
Translation of:Go
programTau_number;{$APPTYPE CONSOLE}usesSystem.SysUtils;functionCountDivisors(n:Integer):Integer;beginResult:=0;vari:=1;vark:=2;if(nmod2)=0thenk:=1;whilei*i<=ndobeginif(nmodi)=0thenbegininc(Result);varj:=ndivi;ifj<>itheninc(Result);end;inc(i,k);end;end;beginWriteln('The first 100 tau numbers are:');varcount:=0;vari:=1;whilecount<100dobeginvartf:=CountDivisors(i);ifimodtf=0thenbeginwrite(format('%4d ',[i]));inc(count);ifcountmod10=0thenwriteln;end;inc(i);end;{$IFNDEF UNIX}readln;{$ENDIF}end.

Draco

/* Generate a table of the amount of divisors for each number */proc nonrec div_count([*]word divs) void:    word max, i, j;    max := dim(divs,1)-1;    divs[0] := 0;    for i from 1 upto max do divs[i] := 1 od;    for i from 2 upto max do        for j from i by i upto max do            divs[j] := divs[j] + 1        od    odcorp/* Find Tau numbers */proc nonrec main() void:    [1100]word divs;    word n, seen;        div_count(divs);    seen := 0;    n := 0;        while n := n + 1; seen < 100 do        if n % divs[n] = 0 then            seen := seen + 1;            write(n:5);            if seen % 10 = 0 then writeln() fi        fi    odcorp
Output:
    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 1016 1040 1044 1048 1056 1068 1089 1096

EasyLang

func cntdiv n .   i = 1   while i <= sqrt n      if n mod i = 0         cnt += 1         if i <> n div i            cnt += 1         .      .      i += 1   .   return cnt.i = 1while n < 100   if i mod cntdiv i = 0      write i & " "      n += 1   .   i += 1.

F#

This task uses [Tau_function#F.23]

// Tau number. Nigel Galloway: March 9th., 2021Seq.initInfinite((+)1)|>Seq.filter(funn->n%(taun)=0)|>Seq.take100|>Seq.iter(printf"%d ");printfn""
Output:
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 1016 1040 1044 1048 1056 1068 1089 1096

Factor

Works with:Factor version 0.99 2020-08-14
USING:assocsgroupingiokernellistslists.lazymathmath.functionsmath.primes.factorsprettyprintsequencessequences.extras;:tau(n--count)group-factorsvalues[1+]map-product;:tau?(n--?)duptaudivisor?;:taus(--list)1lfrom[tau?]lfilter;! Task"The first 100 tau numbers are:"print100tausltakelist>array10groupsimple-table.
Output:
The first 100 tau numbers are:1   2   8    9    12   18   24   36   40   5660  72  80   84   88   96   104  108  128  132136 152 156  180  184  204  225  228  232  240248 252 276  288  296  328  344  348  360  372376 384 396  424  441  444  448  450  468  472480 488 492  504  516  536  560  564  568  584600 612 625  632  636  640  664  672  684  708712 720 732  776  792  804  808  824  828  852856 864 872  876  880  882  896  904  936  948972 996 1016 1040 1044 1048 1056 1068 1089 1096

Fennel

Translation of:ALGOL 68
(do;;; find the count of the divisors of the first 100 positive integers; returns the number of divisors of v(fndivisor-count[v](var(totaln)(values1v)); Deal with powers of 2 first(while(=0(%n2))(settotal(+total1))(setn(math.floor(/n2)))); Odd prime factors up to the square root(varp1)(while(do(setp(+p2))(<=(*pp)n))(varcount1)(while(=0(%np))(set count(+ count1))(setn(math.floor(/np))))(settotal(*totalcount))); If n > 1 then it's prime(when(>n1)(settotal(*total2)))total)(do(locallimit100)(print(.."The first "limit" tau numbers:"))(var(countn)(values00))(while(< countlimit)(setn(+n1))(when(=0(%n(divisor-countn)))(set count(+ count1))(io.write(string.format"%5d%s"n(if(=0(%count10))"\n";else" ")))))))
Output:
The first 100 tau numbers:    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  1016  1040  1044  1048  1056  1068  1089  1096

Fermat

Func Istau(t) =    if t<3 then Return(1) else        numdiv:=2;        for q = 2 to t\2 do            if Divides(q, t) then numdiv:=numdiv+1 fi;        od;        if Divides(numdiv, t)=1 then Return(1) else Return(0) fi;    fi;    .;numtau:=0;i:=0;while numtau<100 do    i:=i+1;    if Istau(i) = 1 then        numtau:=numtau+1;        !(i,'   ');        if Divides(10, numtau) then !! fi;    fi;od;

Forth

Translation of:C++
:divisor_count( n -- n )1>rbegindup2mod0=whiler>1+>r2/repeat3begin2dupdup*>=while1>rbegin2dupmod0=whiler>1+>rtuck/swaprepeat2r>*>r2+repeatdrop1>ifr>2*elser>then;:print_tau_numbers( n -- )."The first"dup.."tau numbers are:"cr0>r1beginoverr@>whiledupdupdivisor_countmod0=ifdup6.rr>1+dup10mod0=ifcrelsespacethen>rthen1+repeat2droprdrop;100print_tau_numbersbye
Output:
The first 100 tau numbers are:     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   1016   1040   1044   1048   1056   1068   1089   1096

Free Pascal

Based on Delphi, but without inlined variables or unit dependencies.
programTau_number;{$mode objfpc}functionCountDivisors(n:Integer):Integer;inline;vari:integer=1;k:integer=2;j:integer;beginResult:=0;if(nmod2)=0thenk:=1;whilei*i<=ndobeginif(nmodi)=0thenbegininc(Result);j:=ndivi;ifj<>itheninc(Result);end;inc(i,k);end;end;varcount:integer=0;i:integer=1;tf:integer;beginWriteln('The first 100 tau numbers are:');whilecount<100dobegintf:=CountDivisors(i);ifimodtf=0thenbeginwrite(i:5);inc(count);ifcountmod10=0thenwriteln;end;inc(i);end;readln;end.
Output:
The first 100 tau numbers are:   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 1016 1040 1044 1048 1056 1068 1089 1096

FreeBASIC

functionnumdiv(nasuinteger)asuintegerdimasuintegerc=2foriasuinteger=2to(n+1)\2ifnmodi=0thenc+=1nextireturncendfunctionfunctionistau(nasuinteger)asbooleanifn=1thenreturntrueifnmodnumdiv(n)=0thenreturntrueelsereturnfalseendfunctiondimasuintegerc=0,i=1whilec<100ifistau(i)thenprinti,c+=1ifcmod10=0thenprintendifi+=1wend
Output:
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           1016          1040          1044          1048          1056          1068          1089          1096

FutureBasic

Using FutureBasic 7.0.34

//// Tau Numbers////FutureBasic 7.0.34, August 2025 R.W////-------------------------------------//// Given an integer, returns the// Tau positive integerlocal fn Tau( n as Int) as Int  int x, result  if n < 3    result = n  else    result = 2    for x = 2 to fix((n + 1) / 2)      if n % x == 0 then result++    next x  end ifend fn = result// Returns True if n is a Tau numberlocal fn isTau(n as Int) as boolean  boolean result = _False  if n % fn Tau(n) == 0 then result = _Trueend fn = resultwindow 1,@"Tau numbers"printprint " First 100 Tau numbers:"printint x, c, resc = 1: x = 1while c < 100  if fn isTau(x)    print using "######";x;    if (c % 9 == 0) then print    c++  end if  x++wendhandleEvents//
Output:
 First 100 Tau numbers:     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  1016  1040  1044  1048  1056  1068  1089

Frink

tau = {|x| x mod length[allFactors[x]] == 0}println[formatTable[columnize[first[select[count[1], tau], 100], 10], "right"]]
Output:
  1   2    8    9   12   18   24   36   40   56 60  72   80   84   88   96  104  108  128  132136 152  156  180  184  204  225  228  232  240248 252  276  288  296  328  344  348  360  372376 384  396  424  441  444  448  450  468  472480 488  492  504  516  536  560  564  568  584600 612  625  632  636  640  664  672  684  708712 720  732  776  792  804  808  824  828  852856 864  872  876  880  882  896  904  936  948972 996 1016 1040 1044 1048 1056 1068 1089 1096

Go

packagemainimport"fmt"funccountDivisors(nint)int{count:=0i:=1k:=2ifn%2==0{k=1}fori*i<=n{ifn%i==0{count++j:=n/iifj!=i{count++}}i+=k}returncount}funcmain(){fmt.Println("The first 100 tau numbers are:")count:=0i:=1forcount<100{tf:=countDivisors(i)ifi%tf==0{fmt.Printf("%4d  ",i)count++ifcount%10==0{fmt.Println()}}i++}}
Output:
The first 100 tau numbers are:   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  1016  1040  1044  1048  1056  1068  1089  1096

Haskell

tau::Integrala=>a->ataun|n<=0=error"Not a positive integer"taun=go0(1,1)whereyoi=(i,i*i)gor(i,ii)|n<ii=r|n==ii=r+1|0==modni=go(r+2)(yo$i+1)|otherwise=gor(yo$i+1)isTau::Integrala=>a->BoolisTaun=0==modn(taun)main=print.take100.filterisTau$[1..]
Output:
[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,1016,1040,1044,1048,1056,1068,1089,1096]


and we could also define Tau numbers in terms of a more generaldivisors function:

importData.List(group,scanl)importData.List.Split(chunksOf)importData.Numbers.Primes(primeFactors)----------------------- TAU NUMBERS ----------------------tauNumbers::[Int]tauNumbers=filter((0==).(rem<*>(length.divisors)))[1..]--------------------------- TEST -------------------------main::IO()main=letxs=take100$fmapshowtauNumbersw=length$lastxsin(putStrLn.unlines)$unwords.fmap(justifyRightw' ')<$>chunksOf10xs------------------------- GENERIC ------------------------divisors::Int->[Int]divisors=foldr(flip((<*>).fmap(*)).scanl(*)1)[1].group.primeFactorsjustifyRight::Int->Char->String->StringjustifyRightnc=(drop.length)<*>(replicatenc<>)
Output:
   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 1016 1040 1044 1048 1056 1068 1089 1096

HPPPL

Works with:HP Prime calculator
Translation of:Run BASIC
EXPORTTau_number()BEGINPRINT();PRINT("Primeros 100 números Tau:");LOCALN:=0;LOCALM:=0;LOCALL:=100;LOCALI:=0;LOCALS:="";WHILEM<LDON:=N+1;T:=0;FORIFROM1TONDOIFNMODI==0THENT:=T+1;END;END;IFNMODT==0THENM:=M+1;IFM>=LTHENS:=S+N;ELSES:=S+N+", ";END;END;END;PRINT(S);PRINT("<fin>")END;
Output:
Primeros 100 números Tau: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, 1016, 1040, 1044,1048, 1056, 1068, 1089, 1096<fin>

Icon andUnicon

The following works in both languages.

proceduremain()everywrites(" ",tau(seq(1))\100|"\n")endproceduretau(n)return((n%ndivs(n))=0,n)endprocedurendivs(n)every(c:=0,n%(1ton)=0,c+:=1)returncend

Output:

 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 1016 1040 1044 1048 1056 1068 1089 1096

J

Implementation:

tau_number=:0=(|~tally_factors@>)tally_factors=:[:*/1+_&q:

Explanation: _ q: produces a list of the exponents of the prime factors of a number. The product of 1 + this list is the number of positive factors of that number. We have a tau number if the remainder of the number divided by that factor count is zero.

In the task example, we generate a list of the first 2000 positive integers and then use an expression of the form (#~ test) which filters a list of numbers based on that test. We then extract the first 100 of these in a 4 row 25 column table.

Task example:

(i.425){(#~tau_number)1+i.2000128912182436405660728084889610410812813213615215618018420422522823224024825227628829632834434836037237638439642444144444845046847248048849250451653656056456858460061262563263664066467268470871272073277679280480882482885285686487287688088289690493694897299610161040104410481056106810891096

Java

Translation of:D
publicclassTau{privatestaticlongdivisorCount(longn){longtotal=1;// Deal with powers of 2 firstfor(;(n&1)==0;n>>=1){++total;}// Odd prime factors up to the square rootfor(longp=3;p*p<=n;p+=2){longcount=1;for(;n%p==0;n/=p){++count;}total*=count;}// If n > 1 then it's primeif(n>1){total*=2;}returntotal;}publicstaticvoidmain(String[]args){finallonglimit=100;System.out.printf("The first %d tau numbers are:%n",limit);longcount=0;for(longn=1;count<limit;++n){if(n%divisorCount(n)==0){System.out.printf("%6d",n);++count;if(count%10==0){System.out.println();}}}}}
Output:
The first 100 tau numbers are:     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  1016  1040  1044  1048  1056  1068  1089  1096

JavaScript

Translation of:ALGOL 60
// Tau number// Return the Tau (number of divisors) of nfunctiontau(n){vart,limit;if(n<3){t=n;}else{t=2;limit=Math.floor((n+1)/2);for(vari=2;i<=limit;i++)if(n%i==0)t++;}returnt;}console.log("First 100 Tau numbers:");varc=0,p=c%10;vari=1;varout=newArray(10);while(c<100){if(i%tau(i)==0){out[p]=i.toString().padStart(5,' ');c++;p=c%10;if(p==0)console.log(out.join(""));}i++;}console.log();
Output:
First 100 Tau numbers:      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 1016 1040 1044 1048 1056 1068 1089 1096

jq

Works with:jq

Works with gojq, the Go implementation of jq

Preliminaries

Seehttps://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-printingdef 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

def taus: range(1;infinite) | select(. % count(divisors) == 0);# The first 100 Tau numbers:[limit(100; taus)]| nwise(10) | map(lpad(4)) | join(" ")
Output:
   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 1016 1040 1044 1048 1056 1068 1089 1096

Julia

usingPrimesfunctionnumfactors(n)f=[one(n)]for(p,e)infactor(n)f=reduce(vcat,[f*p^jforjin1:e],init=f)endlength(f)endfunctiontaunumbers(toget=100)n=0foriin1:100000000ifi%numfactors(i)==0n+=1print(rpad(i,5),n%20==0?"\n":"")n==toget&&breakendendendtaunumbers()
Output:
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  1016 1040 1044 1048 1056 1068 1089 1096

Lua

Translation of:C
functiondivisor_count(n)localtotal=1-- Deal with powers of 2 firstwhile(n&1)==0dototal=total+1n=n>>1end-- Odd prime factors up to the square rootlocalp=3whilep*p<=ndolocalcount=1whilen%p==0docount=count+1n=math.floor(n/p)endtotal=total*countp=p+2end-- If n > 1 then it's primeifn>1thentotal=total*2endreturntotalendlocallimit=100localcount=0print("The first "..limit.." tau numbers are:")localn=1whilecount<limitdoifn%divisor_count(n)==0thenio.write(string.format("%6d",n))count=count+1ifcount%10==0thenprint()endendn=n+1end
Output:
The first 100 tau numbers are:   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  1016  1040  1044  1048  1056  1068  1089  1096

M2000 Interpreter

module tau_numbers {print "The first 100 tau numbers are:"long n, num, limit=100, tau, mwhile num < limitn++:tau=0for m=1 to n{if n mod m=0 then tau++}if n mod tau= 0 else continuenum++:if num mod 10 = 1 then printprint format$("{0::-5}",n);end whileprint}profilertau_numbersprint timecount
Output:
The first 100 tau numbers:    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 1016 1040 1044 1048 1056 1068 1089 1096

MAD

            NORMAL MODE IS INTEGER                        INTERNAL FUNCTION(N)                ENTRY TO POSDIV.                COUNT = 1                THROUGH DIV, FOR I=2, 1, I.G.NDIV             WHENEVER N/I*I.E.N, COUNT = COUNT+1                FUNCTION RETURN COUNT            END OF FUNCTION                        SEEN=0            THROUGH TAU, FOR X=1, 1, SEEN.GE.100            DIVS=POSDIV.(X)            WHENEVER X/DIVS*DIVS.E.X                PRINT FORMAT NUM,X                SEEN = SEEN+1TAU         END OF CONDITIONAL            VECTOR VALUES NUM = $I4*$            END OF PROGRAM
Output:
   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 99610161040104410481056106810891096

Mathematica /Wolfram Language

Take[Select[Range[10000],Divisible[#,Length[Divisors[#]]]&],100]
Output:
{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,1016,1040,1044,1048,1056,1068,1089,1096}

Maxima

taup(n):=integerp(n/cardinality(divisors(n)))$block(count:0,n:1,whilecount<100do(iftaup(n)thenblock(sprint(n),count:count+1,ifmod(count,10)=0thennewline()),n:n+1))$
Output:
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 1016 1040 1044 1048 1056 1068 1089 1096

MiniScript

isTauNumber=function(n)ans=0i=1whilei*i<=nifn%i==0thenans+=1j=floor(n/i)ifj!=ithenans+=1endifi+=1endwhilereturn(n%ans)==0endfunctiontauNums=[]i=1whiletauNums.len<100ifisTauNumber(i)thentauNums.push(i)i+=1endwhileprinttauNums.join(", ")
Output:
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, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096

Modula-2

MODULETauNumbers;FROMInOutIMPORTWriteCard,WriteLn;CONSTMaxNum=1100;(* enough to generate 100 Tau numbers *)NumTau=100;(* how many Tau numbers to generate *)VARDivCount:ARRAY[1..MaxNum]OFCARDINAL;seen,n:CARDINAL;(* Find the amount of divisors for each number beforehand *)PROCEDURECountDivisors;VARi,j:CARDINAL;BEGINFORi:=1TOMaxNumDODivCount[i]:=1;(* every number is divisible by 1 *)END;FORi:=2TOMaxNumDOj:=i;WHILEj<=MaxNumDO(* J is divisible by I *)DivCount[j]:=DivCount[j]+1;j:=j+i;(* next multiple of i *)END;END;ENDCountDivisors;BEGINCountDivisors();n:=1;seen:=0;WHILEseen<NumTauDOIFnMODDivCount[n]=0THENWriteCard(n,5);INC(seen);IFseenMOD10=0THENWriteLn();END;END;INC(n);END;ENDTauNumbers.
Output:
    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 1016 1040 1044 1048 1056 1068 1089 1096

Nim

importmath,strutilsfuncdivcount(n:Natural):Natural=foriin1..sqrt(n.toFloat).int:ifnmodi==0:incresultifndivi!=i:incresultvarcount=0varn=1vartauNumbers:seq[Natural]whiletrue:ifnmoddivcount(n)==0:tauNumbers.addninccountifcount==100:breakincnecho"First 100 tau numbers:"fori,nintauNumbers:stdout.write($n).align(5)ifimod20==19:echo()
Output:
First 100 tau numbers:    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 1016 1040 1044 1048 1056 1068 1089 1096

Oberon-2

Translation of:Modula-2
MODULETauNumbers;IMPORTOut;CONSTMaxNum=1100;NumTau=100;VARdivcount:ARRAYMaxNumOFLONGINT;(* enough to generate 100 Tau numbers *)seen,n:LONGINT;(* how many Tau numbers to generate *)(* Find the amount of divisors for each number beforehand *)PROCEDURECountDivisors;VARi,j:LONGINT;BEGINFORi:=0TOLEN(divcount)-1DOdivcount[i]:=1END;FORi:=2TOLEN(divcount)-1DOj:=i;WHILEj<=LEN(divcount)-1DO(* j is divisible by i *)INC(divcount[j]);INC(j,i)(* next multiple of i *)ENDEND;ENDCountDivisors;BEGINCountDivisors;n:=1;seen:=0;WHILEseen<NumTauDOIFnMODdivcount[n]=0THENOut.Int(n,5);INC(seen);IFseenMOD10=0THENOut.LnENDEND;INC(n)ENDENDTauNumbers.
Output:
    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 1016 1040 1044 1048 1056 1068 1089 1096


PARI/GP

Translation of:Mathematica
{    mylist = []; \\ Initialize an empty list    for (n=1, 10000, \\ Iterate from 1 to 10000        if (n % numdiv(n) == 0, \\ Check if n is divisible by the number of its divisors            mylist = concat(mylist, [n]); \\ If so, append n to the list            if (#mylist == 100, break); \\ Break the loop if we've collected 100 numbers        )    );    print1(mylist); \\ Return the list}
Output:
[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, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096]

Pascal

Free Pascal

programTau_number;{$IFDEF Windows}{$APPTYPE CONSOLE}{$ENDIF}functionCountDivisors(n:NativeUint):integer;//tau functionvarq,p,cnt,divcnt:NativeUint;begindivCnt:=1;ifn>1thenbegincnt:=1;whilenot(Odd(n))dobeginn:=nshr1;divCnt+=cnt;end;p:=3;whilep*p<=ndobegincnt:=divCnt;q:=ndivp;whileq*p=ndobeginn:=q;q:=ndivp;divCnt+=cnt;end;Inc(p,2);end;ifn<>1thendivCnt+=divCnt;end;CountDivisors:=divCnt;end;constUPPERLIMIT=100;varcnt,n:NativeUint;begincnt:=0;n:=1;repeatifnMODCountDivisors(n)=0thenBeginwrite(n:5);inc(cnt);ifcntMod10=0thenwriteln;end;inc(n);untilcnt>=UPPERLIMIT;writeln;{$Ifdef Windows}readln;{$ENDIF}end.
TIO.RUN:
    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 1016 1040 1044 1048 1056 1068 1089 1096

Pascal-P

Translation of:ALGOL 60
Works with:Pascal-P version P4
programtaunum(output);(* Tau number *)vari,c:integer;(* return the Tau (number of divisors) of n *)functiontau(n:integer):integer;vari,t,limit:integer;beginifn<3thent:=nelsebegint:=2;limit:=(n+1)div2;fori:=2tolimitdoifnmodi=0thent:=t+1;end;tau:=t;end;beginwriteln('First 100 Tau numbers:');c:=0;i:=1;whilec<100dobeginifimodtau(i)=0thenbeginwrite(i:5);c:=c+1;ifcmod10=0thenwriteln;end;i:=i+1;end;(* readln; *)end.
Output:
First 100 Tau numbers:    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 1016 1040 1044 1048 1056 1068 1089 1096

PascalABC.NET

##functionDivisorsCount(n:integer):=Range(1,n).Count(i->n.Divs(i));varlst:=newList<integer>;varn:=1;whilelst.Count<100dobeginifn.Divs(DivisorsCount(n))thenlst.Add(n);n+=1;end;lst.Println;
Output:
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 1016 1040 1044 1048 1056 1068 1089 1096


Perl

Library:ntheory
usestrict;usewarnings;usefeature'say';usentheory'divisors';my(@x,$n);do{push(@x,$n)unless$n%scalar(divisors(++$n))}until100==@x;say"Tau numbers - first 100:\n".((sprintf"@{['%5d' x 100]}",@x[0..100-1])=~s/(.{80})/$1\n/gr);
Output:
    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 1016 1040 1044 1048 1056 1068 1089 1096

Phix

imperative

integern=1,found=0whilefound<100doifremainder(n,length(factors(n,1)))=0thenfound+=1printf(1,"%,6d",n)ifremainder(found,10)=0thenputs(1,"\n")endifendifn+=1endwhile
Output:
     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

functional/memoised

same output

sequencetau_cache={1}functiontau(integern)whilen>length(tau_cache)dointegernt=tau_cache[$]+1whileremainder(nt,length(factors(nt,1)))!=0dont+=1endwhiletau_cache&=ntendwhilereturntau_cache[n]endfunctionputs(1,join_by(apply(true,sprintf,{{"%,6d"},apply(tagset(100),tau)}),1,10,""))

PHP

Translation of:ALGOL 60
<?php// Tau number// return the Tau (number of divisors) of $nfunctiontau(int$n):int{if($n<3){$t=$n;}else{$t=2;$limit=intdiv($n+1,2);for($i=2;$i<=$limit;$i++)if($n%$i==0)$t++;}return$t;}echo'First 100 Tau numbers:'.PHP_EOL;$c=0;$i=1;while($c<100){if($i%tau($i)==0){echostr_pad($i,5,' ',STR_PAD_LEFT);$c++;if($c%10==0)echoPHP_EOL;}$i++;}echoPHP_EOL;?>
Output:
First 100 Tau numbers:    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 1016 1040 1044 1048 1056 1068 1089 1096

PILOT

T :1C :n=2C :seen=1C :max=100*numberC :c=1C :i=1*divisorC (n=i*(n/i)):c=c+1C :i=i+1J (i<=n/2):*divisorT (n=c*(n/c)):#nC (n=c*(n/c)):seen=seen+1C :n=n+1J (seen<max):*numberE :
Output:
128912182436405660728084889610410812813213615215618018420422522823224024825227628829632834434836037237638439642444144444845046847248048849250451653656056456858460061262563263664066467268470871272073277679280480882482885285686487287688088289690493694897299610161040104410481056106810891096

PL/I

Translation of:ALGOL 60
Works with:PL/I-86 version 1.0
/* Tau number */tau_numbers:  procedure options(main);  declare    (i, c) fixed binary(15);  put list('First 100 Tau numbers:');  put skip;  c = 0;  i = 1;  do while (c < 100);    if mod(i, tau(i)) = 0 then do;      put edit(i)(f(5));      c = c + 1;      if mod(c, 10) = 0 then        put skip;    end;    i = i + 1;  end;  tau:     procedure (n) returns (fixed binary(15));    /* Return the Tau (number of divisors) of n */    declare      n fixed binary(15),      (i, t, limit) fixed binary(15);    if n < 3 then      t = n;    else do;      t = 2;      limit = (n + 1) / 2;      do i = 2 to limit;        if mod(n, i) = 0 then          t = t + 1;      end;    end;    return (t);  end tau;end tau_numbers;
Output:
First 100 Tau numbers:    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 1016 1040 1044 1048 1056 1068 1089 1096

PL/M

100H:BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;/* PRINT NUMBER RIGHT-ALIGNED IN 7 POSITIONS */PRINT$NUMBER: PROCEDURE (N);    DECLARE S (7) BYTE INITIAL (' .....$');    DECLARE N ADDRESS, I BYTE;    I = 6;DIGIT:    I = I - 1;    S(I) = N MOD 10 + '0';    N = N / 10;    IF N > 0 THEN GO TO DIGIT;    DO WHILE I <> 0;        I = I - 1;        S(I) = ' ';    END;    CALL PRINT(.S);END PRINT$NUMBER;/* COUNT AND STORE AMOUNT OF DIVISORS FOR 1..N AT VEC */COUNT$DIVS: PROCEDURE (VEC, N);    DECLARE (VEC, N, V BASED VEC) ADDRESS;    DECLARE (I, J) ADDRESS;        DO I=1 TO N;        V(I) = 1;    END;        DO I=2 TO N;        J = I;        DO WHILE J <= N;            V(J) = V(J) + 1;            J = J + I;        END;    END;END COUNT$DIVS;/* GIVEN VECTOR OF COUNT OF DIVISORS, SEE IF N IS A TAU NUMBER */TAU: PROCEDURE (VEC, N) BYTE;    DECLARE (VEC, N, V BASED VEC) ADDRESS;    RETURN N MOD V(N) = 0;END TAU;DECLARE AMOUNT LITERALLY '100';DECLARE LIMIT LITERALLY '1100';DECLARE SEEN BYTE INITIAL (0);DECLARE N ADDRESS INITIAL (1);CALL COUNT$DIVS(.MEMORY, LIMIT);DO WHILE SEEN < AMOUNT;    IF TAU(.MEMORY, N) THEN DO;        CALL PRINT$NUMBER(N);        SEEN = SEEN + 1;        IF SEEN MOD 10 = 0 THEN CALL PRINT(.(13,10,'$'));    END;    N = N + 1;END;CALL EXIT;EOF
Output:
     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  1016  1040  1044  1048  1056  1068  1089  1096

Pluto

Library:Pluto-int
Library:Pluto-fmt
localint=require"int"localfmt=require"fmt"locallimit<const>=100localtau={}locali=0print($"The first {limit} tau numbers are:")repeat++ilocaldc=int.divstat(i)[1]ifi%dc==0thentau:insert(i)enduntil#tau==limitfmt.tprint("%4d ",tau,10)
Output:
The first 100 tau numbers are:   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  1016  1040  1044  1048  1056  1068  1089  1096

Prolog

Works with:GNU Prolog
Works with:SWI Prolog
tau(N,T):-findall(M,(between(1,N,M),0isNmodM),Ms),length(Ms,T).tau_numbers(Limit,Ns):-findall(N,(between(1,Limit,N),tau(N,T),0isNmodT),Ns).print_tau_numbers:-tau_numbers(1100,Ns),writeln("The first 100 tau numbers are:"),forall(member(N,Ns),format("~d ",[N])).:-print_tau_numbers.

PureBasic

Translation of:FreeBasic
OpenConsole()Procedure.inumdiv(n)c=2Fori=2To(n+1)/2:Ifn%i=0:c+1:EndIf:NextProcedureReturncEndProcedureProcedure.bistau(n)Ifn=1:ProcedureReturn#True:EndIfIfn%numdiv(n)=0:ProcedureReturn#True:Else:ProcedureReturn#False:EndIfEndProcedurec=0:i=1Whilec<100Ifistau(i):Print(RSet(Str(i),4)+#TAB$):c+1:Ifc%10=0:PrintN(""):EndIf:EndIfi+1WendInput()
Output:
   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 99610161040104410481056106810891096

Python

Python: Procedural

deftau(n):assert(isinstance(n,int)and0<n)ans,i,j=0,1,1whilei*i<=n:if0==n%i:ans+=1j=n//iifj!=i:ans+=1i+=1returnansdefis_tau_number(n):assert(isinstance(n,int))ifn<=0:returnFalsereturn0==n%tau(n)if__name__=="__main__":n=1ans=[]whilelen(ans)<100:ifis_tau_number(n):ans.append(n)n+=1print(ans)
Output:
[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, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096]

Python: Functional

Composing pure functions, and defining a non-finite stream of Tau numbers in terms of a generic `divisors` function:

'''Tau numbers'''fromoperatorimportmulfrommathimportfloor,sqrtfromfunctoolsimportreducefromitertoolsimport(accumulate,chain,count,groupby,islice,product)# tauNumbers :: Generator [Int]deftauNumbers():'''Positive integers divisible by the       count of their positive divisors.    '''return(nfornincount(1)if0==n%len(divisors(n)))# ------------------------- TEST -------------------------# main :: IO ()defmain():'''The first hundred Tau numbers.    '''xs=take(100)(tauNumbers())w=len(str(xs[-1]))print('\n'.join([' '.join([str(cell).rjust(w,' ')forcellinrow])forrowinchunksOf(10)(xs)]))# ----------------------- GENERIC ------------------------# chunksOf :: Int -> [a] -> [[a]]defchunksOf(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.    '''defgo(xs):return(xs[i:n+i]foriinrange(0,len(xs),n))if0<nelseNonereturngo# divisors :: Int -> [Int]defdivisors(n):'''The ordered divisors of n.    '''defgo(a,x):return[a*bfora,binproduct(a,accumulate(chain([1],x),mul))]returnsorted(reduce(go,[list(g)for_,gingroupby(primeFactors(n))],[1]))if1<nelse[1]# primeFactors :: Int -> [Int]defprimeFactors(n):'''A list of the prime factors of n.    '''deff(qr):r=qr[1]returnstep(r),1+rdefstep(x):return1+(x<<2)-((x>>1)<<1)defgo(x):root=floor(sqrt(x))defp(qr):q=qr[0]returnroot<qor0==(x%q)q=until(p)(f)((2if0==x%2else3,1))[0]return[x]ifq>rootelse[q]+go(x//q)returngo(n)# take :: Int -> [a] -> [a]# take :: Int -> String -> Stringdeftake(n):'''The prefix of xs of length n,       or xs itself if n > length xs.    '''defgo(xs):return(xs[0:n]ifisinstance(xs,(list,tuple))elselist(islice(xs,n)))returngo# until :: (a -> Bool) -> (a -> a) -> a -> adefuntil(p):'''The result of repeatedly applying f until p holds.       The initial seed value is x.    '''defgo(f):defg(x):v=xwhilenotp(v):v=f(v)returnvreturngreturngo# MAIN ---if__name__=='__main__':main()
Output:
   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 1016 1040 1044 1048 1056 1068 1089 1096

Quackery

factors is defined atFactors of an integer#Quackery.

  [ dup factors size mod 0 = ] is taunumber ( n --> b )  [] 0  [ 1+ dup taunumber if      [ tuck join swap ]    over size 100 = until ]  drop  [] swap   witheach [ number$ nested join ]  80 wrap$
Output:
1 2 8 9 12 18 24 36 40 56 60 72 80 84 88 96 104 108 128 132 136 152 156 180 184204 225 228 232 240 248 252 276 288 296 328 344 348 360 372 376 384 396 424 441444 448 450 468 472 480 488 492 504 516 536 560 564 568 584 600 612 625 632 636640 664 672 684 708 712 720 732 776 792 804 808 824 828 852 856 864 872 876 880882 896 904 936 948 972 996 1016 1040 1044 1048 1056 1068 1089 1096

R

tau<-function(t){results<-integer(0)resultsCount<-0n<-1while(resultsCount!=t){condition<-function(n)(n%%length(c(Filter(function(x)n%%x==0,seq_len(n%/%2)),n)))==0if(condition(n)){resultsCount<-resultsCount+1results[resultsCount]<-n}n<-n+1}results}tau(100)

Racket

#langracket(definelimit100)(define(divisor-countn)(length(filter(λ(x)(zero?(remaindernx)))(range1(+1n)))))(define(display-tau-numbers(n1)(count1))(when(<=countlimit)(if(zero?(remaindern(divisor-countn)))(begin(printf(~an#:width5#:align'right))(when(zero?(remaindercount10))(newline))(display-tau-numbers(add1n)(add1count)))(display-tau-numbers(add1n)count))))(printf"The first ~a Τau numbers are~n"limit)(display-tau-numbers)
Output:
The first 100 Τau numbers are    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 1016 1040 1044 1048 1056 1068 1089 1096

Raku

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

usePrime::Factor:ver<0.3.0+>;useLingua::EN::Numbers;say"\nTau function - first 100:\n",# ID(1..*).map({ +.&divisors })[^100]\# the task.batch(20)».fmt("%3d").join("\n");# display formattingsay"\nTau numbers - first 100:\n",# ID(1..*).grep({$_ %% +.&divisors })[^100]\# the task.batch(10)».&comma».fmt("%5s").join("\n");# display formattingsay"\nDivisor sums - first 100:\n",# ID(1..*).map({ [+] .&divisors })[^100]\# the task.batch(20)».fmt("%4d").join("\n");# display formattingsay"\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   9Tau 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,096Divisor 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  217Divisor 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

Version 1

Simplified, use the tau function of the respective task, ooRexx compatible

/*REXX pgm displays N tau numbers (integers divisible by the # of its divisors).  */ParseArgncols./*obtain optional argument from the CL. */Ifn==''|n==','Thenn=100/*Not specified?  Then use the default. */Ifcols==''|cols==','Thencols=10/*Not specified?  Then use the default. */w=6/*W:  used To align 1st output column.  */ttau=' the first 'commas(n)' tau numbers'/* the title of the table.            */Say' index ¦'center(ttau,cols*(w+1))/* display the title                  */Say'-------+'center('',cols*(w+1),'-')idx=1nn=0/* number of tau numbers                */dd=''Doj=1Untilnn==n/* search for   N   tau numbers         */Ifj//tau(j)==0ThenDo/* If this is a tau number              */nn=nn+1/* bump the count of tau numbers found. */dd=ddright(commas(j),w)/* add a tau number To the output list. */Ifnn//cols==0ThenDo/* a line is full                       */Saycenter(idx,7)'¦'substr(dd,2)/* display partial list To the terminal.*/idx=idx+cols/* bump idx by number of cols           */dd=''EndEndEndIfdd\==''ThenSaycenter(idx,7)'¦'substr(dd,2)/*possible display rest         */Say'--------'center('',cols*(w+1),'-')Exit0/*stick a fork in it,we're all done.    *//*--------------------------------------------------------------------------------*/commas:ParseArg?;Dojc=length(?)-3To1by-3;?=insert(',',?,jc);End;Return?/*--------------------------------------------------------------------------------*/tau:ProcedureParseArgxIfx<6Then/* some low numbers are handled special */Return2+(x==4)-(x==1)tau=0odd=x//2Doj=1by1Whilej*j<xIfodd&j//2=0Then/* even j can't be a divisor of an odd x*/IterateIfx//j==0Then/* If no remainder,Then found a divisor*/tau=tau+2/* bump n of divisors                   */EndIfj*j=xThen/* x is a square                        */tau=tau+1/* its root is a divisor                */Returntau
output  when using the default input:
 index ¦                      the first  100  tau numbers-------+----------------------------------------------------------------------   1   ¦      1      2      8      9     12     18     24     36     40     56  11   ¦     60     72     80     84     88     96    104    108    128    132  21   ¦    136    152    156    180    184    204    225    228    232    240  31   ¦    248    252    276    288    296    328    344    348    360    372  41   ¦    376    384    396    424    441    444    448    450    468    472  51   ¦    480    488    492    504    516    536    560    564    568    584  61   ¦    600    612    625    632    636    640    664    672    684    708  71   ¦    712    720    732    776    792    804    808    824    828    852  81   ¦    856    864    872    876    880    882    896    904    936    948  91   ¦    972    996  1,016  1,040  1,044  1,048  1,056  1,068  1,089  1,096------------------------------------------------------------------------------

Version 2

Include:How to use
Include:Source code
Divisor in Special returns the number of divisors.

--24Aug2025includeSettingcallTimer'x'say'TAU NUMBER'sayversionsaycallTask100callTimerexitTask:procedureargxxsay'First'xx' tau numbers...'n=0doi=1untiln=xxa=Divisor(i)ifi//a=0thendon=n+1callCharout,Right(i,5)ifn//10=0thensayendendsayreturnincludeMath
Output:
TAU NUMBERREXX-Regina_3.9.7(MT) 5.00 18 Mar 2025First 100  tau numbers...    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 1016 1040 1044 1048 1056 1068 1089 10960.008 seconds

Ring

see "The first 100 tau numbers are:" + nl + nln = 1num = 0limit = 100while num < limit      n = n + 1      tau = 0      for m = 1 to n          if n%m = 0             tau = tau + 1          ok      next      if n%tau = 0         num = num + 1         if num%10 = 1            see nl         ok         see "" + n + " "      okend

Output:

The first 100 tau numbers are: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 1016 1040 1044 1048 1056 1068 1089 1096

RPL

The tau function has been translated from Python.

≪ → n   ≪ 0 1 1 n √FOR jIF n j MOD NOTTHEN         SWAP 1 + SWAP DROP n j / IPIF DUP j ≠THEN SWAP 1 + SWAPENDENDNEXT DROP ≫ ≫ 'TAU' STO≪ { } 1DOIF DUP DUP TAU MOD NOTTHEN SWAP OVER + SWAPEND       1 +UNTIL OVER SIZE 100 ≥END DROP ≫ 'TAUNB' STO
Output:
{ 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 1016 1040 1044 1048 1056 1068 1089 1096 }

Ruby

require'prime'taus=Enumerator.newdo|y|(1..).eachdo|n|num_divisors=n.prime_division.inject(1){|prod,n|prod*=n[1]+1}y<<nifn%num_divisors==0endendptaus.take(100)
Output:
[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, 1016, 1040, 1044, 1048, 1056, 1068, 1089, 1096]

Rust

/// Gets all divisors of a number, including itselffnget_divisors(n:u32)->Vec<u32>{letmutresults=Vec::new();foriin1..(n/2+1){ifn%i==0{results.push(i);}}results.push(n);results}fnis_tau_number(i:u32)->bool{0==i%get_divisors(i).len()asu32}fnmain(){println!("\nFirst 100 Tau numbers:");letmutcounter:u32=0;letmuti:u32=1;whilecounter<100{ifis_tau_number(i){print!("{:>4}",i);counter+=1;print!("{}",ifcounter%20==0{"\n"}else{","});}i+=1;}}
Output:
First 100 Tau numbers:   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,1016,1040,1044,1048,1056,1068,1089,1096

Scheme

Works with:Racket
Translation of:FreeBASIC
(define(numdivn)(define(loopkc)(if(>kn)c(loop(+k1)(if(=(modulonk)0)(+c1)c))))(loop10))(define(tau?n)(=(modulon(numdivn))0))(define(print-tau)(define(loopic)(cond((=c100)'done)((tau?i)(begin(displayi)(display" ")(when(=(modulo(+c1)10)0)(newline))(loop(+i1)(+c1))))(else(loop(+i1)c))))(display"The first 100 tau numbers are:")(newline)(loop10)(newline))(print-tau)
Output:
The first 100 tau numbers are: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 1016 1040 1044 1048 1056 1068 1089 1096

Sidef

funcis_tau_number(n){n%n.sigma0==0}sayis_tau_number.first(100).join(' ')
Output:
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 1016 1040 1044 1048 1056 1068 1089 1096

Swift

importFoundation// See https://en.wikipedia.org/wiki/Divisor_functionfuncdivisorCount(number:Int)->Int{varn=numbervartotal=1// Deal with powers of 2 firstwhile(n&1)==0{total+=1n>>=1}// Odd prime factors up to the square rootvarp=3whilep*p<=n{varcount=1whilen%p==0{count+=1n/=p}total*=countp+=2}// If n > 1 then it's primeifn>1{total*=2}returntotal}letlimit=100print("The first\(limit) tau numbers are:")varcount=0varn=1whilecount<limit{ifn%divisorCount(number:n)==0{print(String(format:"%5d",n),terminator:"")count+=1ifcount%10==0{print()}}n+=1}
Output:
The first 100 tau numbers are:    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 1016 1040 1044 1048 1056 1068 1089 1096

Verilog

modulemain;integern,m,num,limit,tau;initialbegin$display("The first 100 tau numbers are:\n");n=0;num=0;limit=100;while(num<limit)beginn=n+1;tau=0;for(m=1;m<=n;m=m+1)if(n%m==0)tau=tau+1;if(n%tau==0)beginnum=num+1;if(num%5==1)$display("");$write(n);endend$finish;endendmodule


VTL-2

10 N=110020 I=130 :I)=140 I=I+150 #=N>I*3060 I=270 J=I80 :J)=:J)+190 J=J+I100 #=N>J*80110 I=I+1120 #=N>I*70130 C=0140 I=1150 #=I/:I)*0+0<%*210160 ?=I170 $=9180 C=C+1190 #=C/10*0+0<%*210200 ?=""210 I=I+1220 #=C<100*150
Output:
1       2       8       9       12      18      24      36      40      5660      72      80      84      88      96      104     108     128     132136     152     156     180     184     204     225     228     232     240248     252     276     288     296     328     344     348     360     372376     384     396     424     441     444     448     450     468     472480     488     492     504     516     536     560     564     568     584600     612     625     632     636     640     664     672     684     708712     720     732     776     792     804     808     824     828     852856     864     872     876     880     882     896     904     936     948972     996     1016    1040    1044    1048    1056    1068    1089    1096

Wren

Library:Wren-math
Library:Wren-fmt
import"./math"forIntimport"./fmt"forFmtSystem.print("The first 100 tau numbers are:")varcount=0vari=1while(count<100){vartf=Int.divisors(i).countif(i%tf==0){Fmt.write("$,5d  ",i)count=count+1if(count%10==0)System.print()}i=i+1}
Output:
The first 100 tau numbers are:    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

XPL0

func Divs(N);   \Return number of divisors of Nint  N, D, C;[C:= 0;for D:= 1 to N do    if rem(N/D) = 0 then C:= C+1;return C;];int C, N;[Format(5, 0);C:= 0;  N:= 1;loop    [if rem(N/Divs(N)) = 0 then            [RlOut(0, float(N));            C:= C+1;            if rem(C/10) = 0 then CrLf(0);            if C >= 100 then quit;            ];        N:= N+1;        ];]
Output:
    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 1016 1040 1044 1048 1056 1068 1089 1096
Retrieved from "https://rosettacode.org/wiki/Tau_number?oldid=396790"
Categories:
Hidden category:
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

[8]ページ先頭

©2009-2026 Movatter.jp