Adding optimized implementation of the gcd algorithm.