optimize gcd() for speed