calculating power modulus M using recursion