def modulo_exp(a, n, m):
    """
    Returns (a^n) modulo m
    """
    ans = 1
    while n > 0:
        if (n & 1) == 1:
            ans = (ans * a) % m
        n = n >> 1
        a = (a * a) % m
    return ans