Solution for gcd