How to optimize this code?

problem
my solution

Getting TLE in two test cases …!!!

Any help ??

g(C)=⌊Cp⌋+⌊Cq⌋+⌊Cr⌋−⌊Cqr⌋−⌊Cpr⌋−⌊Cpq⌋+⌊Cpqr⌋

Use the principle of inclusion-exclusion and mask to compute how many numbers are coprime w.r.t X in range (L,R).

I didn’t get ,please share the accepted code if possible …!!