Improve gcd(a, b) where one argument is a power of a symbol.