invModPowerOf2

fnBigInt invModPowerOf2(BigInt n, size_t k) pure @safe

Computes the modular inverse of n modulo a power of 2: n^-1 mod 2^k.

Uses Newton's method to iteratively compute the inverse, doubling precision at each step.

Parameters

nThe value to invert (must be odd for inverse to exist)
kThe power of 2 for the modulus

Returns

n^-1 mod 2^k