Tau number: Difference between revisions
Content deleted Content added
MaiconSoft (talk | contribs) Added Delphi example |
|||
Line 895: | Line 895: | ||
[: */ [: >: [: {: __&q: |
[: */ [: >: [: {: __&q: |
||
</pre> |
</pre> |
||
=={{header|Java}}== |
|||
{{trans|D}} |
|||
<lang java>public class Tau { |
|||
private static long divisorCount(long n) { |
|||
long total = 1; |
|||
// Deal with powers of 2 first |
|||
for (; (n & 1) == 0; n >>= 1) { |
|||
++total; |
|||
} |
|||
// Odd prime factors up to the square root |
|||
for (long p = 3; p * p <= n; p += 2) { |
|||
long count = 1; |
|||
for (; n % p == 0; n /= p) { |
|||
++count; |
|||
} |
|||
total *= count; |
|||
} |
|||
// If n > 1 then it's prime |
|||
if (n > 1) { |
|||
total *= 2; |
|||
} |
|||
return total; |
|||
} |
|||
public static void main(String[] args) { |
|||
final long limit = 100; |
|||
System.out.printf("The first %d tau numbers are:%n", limit); |
|||
long count = 0; |
|||
for (long n = 1; count < limit; ++n) { |
|||
if (n % divisorCount(n) == 0) { |
|||
System.out.printf("%6d", n); |
|||
++count; |
|||
if (count % 10 == 0) { |
|||
System.out.println(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}</lang> |
|||
{{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> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |