RosettaCodeData/Task/Tau-function/Dyalect/tau-function.dyalect

34 lines
593 B
Plaintext

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