Solution to GCD problem using modulus