2014-04-02 16:56:35 +00:00
|
|
|
import std.stdio, std.math, std.range, std.algorithm;
|
2013-04-10 23:57:08 -07:00
|
|
|
|
2014-04-02 16:56:35 +00:00
|
|
|
bool isPerfectNumber2(in int n) pure nothrow {
|
|
|
|
|
if (n < 2)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int total = 1;
|
|
|
|
|
foreach (immutable i; 2 .. cast(int)real(n).sqrt + 1)
|
|
|
|
|
if (n % i == 0) {
|
|
|
|
|
immutable int q = n / i;
|
|
|
|
|
total += i;
|
|
|
|
|
if (q > i)
|
|
|
|
|
total += q;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return total == n;
|
2013-04-10 23:57:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main() {
|
2014-04-02 16:56:35 +00:00
|
|
|
10_000.iota.filter!isPerfectNumber2.writeln;
|
2013-04-10 23:57:08 -07:00
|
|
|
}
|