Good luck running ^4 on larger numbers and overflowing integer / long bounds orders of magnitude faster than the plain "boring" solutions
n^4 % x = m
== (n % x)^4 % x = m
By way of demonstration: n = 18, x = 15
18^4 = 104976 = 6 (mod 15)
----
18 % 15 = 3
3^4 = 81 = 6 (mod 15)
A very handy result to remember for cases where you don't want to use or don't have easy access to arbitrary precision integers.EDIT: Pasting into Lynx screwed formatting from Groff.
That is not generally true. A quick counterexample:
a = 2, n = 3, b = 5
2^3 % 5 = 8 % 5 = 3
2 % 5 = 2
3 != 2 (a ^ n) % n = a % n