gcd algorithm

please review and merge if it's ok :)