gcd and exponentiation recursively