final version for modular exponentiation