Anonymous user
Proper divisors: Difference between revisions
1. Shorter, 2. Supports numbers of any length, as long as you have enough ram, if someone wants to use Longs they can just replace every `BigInt` with a `Long` (and `BigInt(1)` with `1L`, additionally: 3. updated to latest Sala
m (→{{header|VBA}}) |
(1. Shorter, 2. Supports numbers of any length, as long as you have enough ram, if someone wants to use Longs they can just replace every `BigInt` with a `Long` (and `BigInt(1)` with `1L`, additionally: 3. updated to latest Sala) |
||
Line 3,762:
===Proper divisors for big (long) numbers===
<lang Scala>import scala.annotation.tailrec
def factorize(
case false if x % a == 0 => foo(x / a, a, a :: list)
case false => foo(x, a + 1, list)
case true => x :: list
▲ }
}
def properDivisors(n:
val products = (1 until factors.length).flatMap(i => factors.combinations(i).map(_.product).toList).
}</lang>
|