Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
41
Task/Tau-function/Scala/tau-function.scala
Normal file
41
Task/Tau-function/Scala/tau-function.scala
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
object TauFunction {
|
||||
|
||||
private def divisorCount(n: Long): Long = {
|
||||
var count = 1L
|
||||
var number = n
|
||||
|
||||
// Deal with powers of 2 first
|
||||
while ((number & 1L) == 0) {
|
||||
count += 1
|
||||
number >>= 1
|
||||
}
|
||||
|
||||
// Odd prime factors up to the square root
|
||||
var p = 3L
|
||||
while (p * p <= number) {
|
||||
var tempCount = 1L
|
||||
while (number % p == 0) {
|
||||
tempCount += 1
|
||||
number /= p
|
||||
}
|
||||
count *= tempCount
|
||||
p += 2
|
||||
}
|
||||
|
||||
// If n > 1 then it's prime
|
||||
if (number > 1) {
|
||||
count *= 2
|
||||
}
|
||||
|
||||
count
|
||||
}
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
val limit = 100
|
||||
println(s"Count of divisors for the first $limit positive integers:")
|
||||
for (n <- 1 to limit) {
|
||||
print(f"${divisorCount(n)}%3d")
|
||||
if (n % 20 == 0) println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import "/math" for Int
|
||||
import "/fmt" for Fmt
|
||||
import "./math" for Int
|
||||
import "./fmt" for Fmt
|
||||
|
||||
System.print("The tau functions for the first 100 positive integers are:")
|
||||
for (i in 1..100) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue