exponentiation by squaring