Vladik and fractions

CodeForces - 743C