I'm writing a program that is spending major amounts of time of CPU doing power operations. I need to get the modulo of $i^j$ by k. Is there any simplification of $i^j$%k that doesn't involve an exponentiation?
Note: I remove the specification about needing to heck divisibility. I actually need to get the modulo so that I can do more things with it.