Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
27
Task/Arithmetic-numbers/Scala/arithmetic-numbers.scala
Normal file
27
Task/Arithmetic-numbers/Scala/arithmetic-numbers.scala
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
object ArithmeticNumbers extends App {
|
||||
var arithmeticCount = 0
|
||||
var compositeCount = 0
|
||||
var n = 1
|
||||
|
||||
while (arithmeticCount <= 1_000_000) {
|
||||
val factors = findFactors(n)
|
||||
val sum = factors.sum
|
||||
if (sum % factors.size == 0) {
|
||||
arithmeticCount += 1
|
||||
if (factors.size > 2) compositeCount += 1
|
||||
if (arithmeticCount <= 100) {
|
||||
print(f"$n%3d" + (if (arithmeticCount % 10 == 0) "\n" else " "))
|
||||
}
|
||||
if (List(1_000, 10_000, 100_000, 1_000_000).contains(arithmeticCount)) {
|
||||
println()
|
||||
println(s"${arithmeticCount}th arithmetic number is $n")
|
||||
println(s"Number of composite arithmetic numbers <= $n: $compositeCount")
|
||||
}
|
||||
}
|
||||
n += 1
|
||||
}
|
||||
|
||||
def findFactors(number: Int): Set[Int] = {
|
||||
(1 to number).filter(number % _ == 0).toSet
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue