implemented solution to problem 4
using library gcd algorithm