Greatest common divisors near S-units and its applications