sherlock and gcd solution