dkh.numeric.primitive

  • lcm

    Declaration

    T lcm(T)(in T a, in T b);

    lcm

    Examples

    1. assert(lcm(2, 4) == 4); assert(lcm(3, 5) == 15); assert(lcm(1, 1) == 1); assert(lcm(0, 100) == 0);

  • pow

    Declaration

    Unqual!T pow(T, U)(T x, U n) if (!isFloatingPoint!T && (isIntegral!U || is(U == BigInt)));
    Unqual!T pow(T, U, V)(T x, U n, V e) if ((isIntegral!U || is(U == BigInt)) && is(Unqual!T == Unqual!V));

    高速累乗

  • Declaration

    T powMod(T, U, V)(T x, U n, V md) if (isIntegral!U || is(U == BigInt));

  • Declaration

    T[3] extGcd(T)(in T a, in T b) if (!isIntegral!T || isSigned!T);

    a*T[0]+b*T[1]=T[2], T[2]=gcd

    Examples

    1. import std.numeric : gcd; foreach (i; 0..100) { foreach (j; 0..100) { auto e = extGcd(i, j); assert(e[2] == gcd(i, j)); assert(e[0] * i + e[1] * j == e[2]); } }

  • Declaration

    T invMod(T)(T x, T md);

    calc inverse, (x * invMod(x)) % md == 1