Tau number: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) Undo revision 365760 by Walterpachl (talk) Tag: Undo |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 860:
856 864 872 876 880 882 896 904 936 948
972 996 1016 1040 1044 1048 1056 1068 1089 1096
</pre>
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">
internal class Program
{
private static void Main(string[] args)
{
long limit = 100;
Console.WriteLine($"The first {limit} tau numbers are:");
long count = 0;
for (long n = 1; count < limit; ++n)
{
if (IsTauNumber(n))
{
Console.Write($"{n, 6} ");
++count;
if (count % 10 == 0)
{
Console.WriteLine();
}
}
}
}
private static bool IsTauNumber(long n)
{
return n % DivisorCount(n) == 0;
}
private static long DivisorCount(long n)
{
long total = 1;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1)
{
++total;
}
// Odd prime factors up to the square root
for (long p = 3; p * p <= n; p += 2)
{
long count = 1;
for (; n % p == 0; n /= p)
{
++count;
}
total *= count;
}
// If n > 1 then it's prime
if (n > 1)
{
total *= 2;
}
return total;
}
}
</syntaxhighlight>
{{out}}
<pre>
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
</pre>
Line 1,240 ⟶ 1,317:
=={{header|EasyLang}}==
<syntaxhighlight lang=text>
func cntdiv n .
i = 1
Line 2,848 ⟶ 2,925:
=={{header|REXX}}==
Simplified, use the tau function of the respective task, ooRexx compatible
<syntaxhighlight lang="rexx">/*REXX pgm displays N tau numbers (integers divisible by the # of its divisors). */
If cols=='' | cols==',' Then cols= 10 /*Not specified? Then use the default. */
Say '-------+'center('' ,cols*(w+1),'-')
idx=1
nn=0
dd=''
Do j=1 Until nn==n
If j//tau(j)==0 Then Do
nn=nn+1
If nn//cols==0 Then Do
Say center(idx,7)'¦' substr(dd,2) /* display partial list To the terminal.*/
idx= idx+cols /* bump idx by number of cols */
dd=''
End
End
End
If dd\=='' Then Say center(idx,7)'¦' substr(dd,2) /*possible display rest */
Say '--------'center('' ,cols*(w+1),'-')
Exit 0
/*--------------------------------------------------------------------------------*/
commas: Parse Arg ?; Do jc=length(?)-3 To 1 by -3; ?=insert(',',?,jc); End; Return ?
/*--------------------------------------------------------------------------------*/
tau: Procedure
Parse Arg x
If x<6 Then
Return 2+(x==4)-(x==1)
tau=0
odd=x//2
Do j=1 by 1 While j*j<x
If odd &
Iterate
If x//j==0 Then /* If no remainder,Then found a divisor*/
tau=tau+2 /* bump n of divisors */
End
If j*j=x Then /* x is a square */
tau=tau+1 /* its root is a divisor */
Return tau </syntaxhighlight>
{{out|output|text= when using the default input:}}
<pre>
index
-------+----------------------------------------------------------------------
1
11
21
31
41
51
61
71
81
91
------------------------------------------------------------------------------</pre>
=={{header|Ring}}==
|