March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -1,23 +1,17 @@
import std.stdio, std.bigint, std.algorithm, std.traits;
import std.stdio, std.bigint, std.algorithm, std.traits, std.range;
Unqual!T[] decompose(T)(in T number) pure /*nothrow*/
in {
assert(number > 1);
} body {
alias UT = Unqual!T;
typeof(return) result;
UT n = number;
Unqual!T n = number;
for (UT i = 2; n % i == 0;) {
for (Unqual!T i = 2; n % i == 0; n /= i)
result ~= i;
n /= i;
}
for (UT i = 3; n >= i * i; i += 2) {
while (n % i == 0) {
for (Unqual!T i = 3; n >= i * i; i += 2)
for (; n % i == 0; n /= i)
result ~= i;
n /= i;
}
}
if (n != 1)
result ~= n;
@ -25,9 +19,7 @@ in {
}
void main() {
foreach (immutable n; 2 .. 10)
n.decompose.writeln;
writefln("%(%s\n%)", iota(2, 10).map!decompose);
decompose(1023 * 1024).writeln;
BigInt(2 * 3 * 5 * 7 * 11 * 11 * 13 * 17).decompose.writeln;
decompose(16860167264933UL.BigInt * 179951).writeln;