Jump to content

Tau function: Difference between revisions

Added Dart
m (→‎{{header|Wren}}: Minor tidy)
(Added Dart)
Line 1,160:
2 4 6 7 4 8 2 6 4 8 2 12 2 4 6 6 4 8 2 10
5 4 2 12 4 4 4 8 2 12 4 6 4 4 4 12 2 6 6 9</pre>
 
=={{header|Dart}}==
{{trans|C++}}
<syntaxhighlight lang="dart">int divisorCount(int n) {
int total = 1;
// Deal with powers of 2 first
for (; (n & 1) == 0; n >>= 1) total++;
// Odd prime factors up to the square root
for (int p = 3; p * p <= n; p += 2) {
int count = 1;
for (; n % p == 0; n ~/= p) count++;
total *= count;
}
// If n > 1 then it's prime
if (n > 1) total *= 2;
return total;
}
 
void main() {
const int limit = 100;
print("Count of divisors for the first $limit positive integers:");
for (int n = 1; n <= limit; ++n) {
print(divisorCount(n).toString().padLeft(3));
}
}</syntaxhighlight>
 
=={{header|Delphi}}==
2,130

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.