def powMod(p,k,N):
    """
    powMod computes p^k mod N using rapid modular exponentiation.

    Args:
        p (int): The number to be exponentiated.
        k (int): The exponental.
        N (int): The modulus.

    Returns:
        The integer result.
    """
    acc = 1
    r = 0
    for s in range(0,65):
        if s == 0:
            r = p
        else:
            r = (r**2) % N
        kk = 2**s

        if k & (0x01 << s):
            acc = (acc * r) % N

        if 2**(s+1) > k:
            break
    return acc % N