Can be calculated efficiently with the Extended Euclidean algorithm.
math.stackexchange.com/questions/2382011/computational-complexity-of-modular-exponentiation-from-rosens-discrete-mathem mentions:can be calculated in:Remember that and are the lengths in bits of and , so in terms of the length in bits and we'd get: