public static ModNum Pow(ModNum val, ulong count) { return(count == 0 ? new ModNum(1) : count == 1 ? val : count == 2 ? val * val : count % 2 == 0 ? Pow(Pow(val, count / 2), 2) : Pow(Pow(val, count / 2), 2) * val); }
private static ModNum Inverse(ModNum val) { return(Pow(val, mod - 2)); }