def fme(base: int, exponent: int, modulus: int) -> int:
    """ Algorithm for fast modular exponentiation. """
    result = 1
    temp = base % modulus
    while exponent > 0:
        if exponent & 1:
            result = (result * temp) % modulus
        temp = (temp * temp) % modulus
        exponent >>= 1
    return result