Problem in a math related question of codeforces div2 D

https://codeforces.com/contest/1295/problem/D

can anyone plz explain this solution (based on inclusion exclusion principle )
https://codeforces.com/contest/1295/submission/69760075
or
https://codeforces.com/contest/1295/submission/69763365 (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