def modpow(a,e,n):
    """Returns a^e (mod n).
    More efficient for large values than directly computing."""
    if(n<1):
        return -1
    b=bin(e)[2:]
    prod=1
    current=a
    for i in range(len(b)):
        if(b[-i-1]=='1'):
            prod *= current
            prod %= n
        current *= current
        current %= n
    return prod