# Fast modulo operation [duplicate]

Possible Duplicate:
calculating $a^b \!\mod c$

I have a number of form: $p^n + p$, where $p$ is a prime number and $n$ can be any large number, for example, say $10^{12}$.

What is the generic algorithm to compute $(p^n + p) \pmod k$, where $k$ is a huge number say $k=1000000007$.

Thanks!

## marked as duplicate by hardmath, Ross Millikan, Noah Snyder, Chris Eagle, NorbertOct 8 '12 at 9:29

The real question seems to be on $p^n$ mod k where n is large. For that, have a look at Modular Exponentiation on wikipedia.