[ create a new paste ] login | about

Link: http://codepad.org/E9KHKvAi    [ raw code | fork ]

D, pasted on Mar 19:
T[] decompose(T)(T n) /*pure nothrow*/
in {
    assert(n > 1);
} body {
    T[] res;
    for (T i = 2; n % i == 0;) {
        res ~= i;
        n /= i;
    }
    for (T i = 3; n >= i * i; i += 2) {
        while (n % i == 0) {
            res ~= i;
            n /= i;
        }
    }

    if (n != 1)
        res ~= n;

    return res;
}

void main() {
    import std.stdio, std.bigint, std.algorithm;
    writeln(decompose(1023 * 1024));
    writeln(decompose(BigInt(2 * 3 * 5 * 7 * 11 * 11 * 13 * 17)));
    writeln(decompose(BigInt(16860167264933UL) * 179951));
    writeln(group(decompose(BigInt(2) ^^ 100_000)));
}


Create a new paste based on this one


Comments: