Added optimized version for the exponentiation problem