Number Theory - Let's Play Game

https://hack.codingblocks.com/contests/c/126/729

What will be the trick for the above Question?’

I’m using this logic- For a given integer x, you need to find the number of pairs <a,b> such that gcd(a,b)=1. So, you need to find the number of pairs <a, x!/a> such that a ϵ {factors of x!}.

I’m getting time limit exceeded.