Fixed Overflow Issues in gcd, lcm, and Modulo Functions

Fixed possible overflow in gcd , lcm and modulo (% operator) (Maks Skorokhod).