Anonymous user
Factors of an integer: Difference between revisions
Updated D versions
m (→{{header|Mercury}}: Corrected output to match the actual code's functionality.) |
(Updated D versions) |
||
Line 694:
=={{header|D}}==
<lang d>import std.stdio, std.math, std.algorithm;
T[] factor(T)(in T n) /*pure nothrow*/ {
if (n == 1) return [n];
T[] res = [1, n];
T limit = cast(T)
for (T i = 2; i < limit; i++) {
if (n % i == 0) {
res ~= i;
if (q > i)
res ~= q;
}
}
return res.sort().release();
}
Line 726 ⟶ 727:
auto factors(I)(I n) {
return filter!(
}
|