added the optimal gcd algorithm