Use standard gcd implementation with mod instead of -