Problem in a math related question of codeforces div2 D

can anyone plz explain this solution (based on inclusion exclusion principle )

or
Submission #69763365 - Codeforces (not on inclusion exclusion but still kind of same)

This is Euler’s Totient Function. link

that’s 9th grade math tho
#FIITJEE

i qualified RMO XDDD