Fermat and Euler's Theorem: Repeated Squaring Algorithm