The algorithm presented is also called the binary square and multiply method. It reduces the number of operations (multiplies and modulo divisions) to about 1.5 * (log2 x).