we have $\cos^{2m}(y)\in[0,1]$ because $2m$ is even. taking the limit we have $\cos^{2m}(y)\to0$ if $\cos(y)\
e\pm1$ and $\cos^{2m}(y)\to1$ if $\cos(y)=\pm1$.
Now, $\cos(y)=\pm1$ iff $y=N\pi,N\in\Bbb Z$ so $\lim_{m\to\infty}\cos^{2m}(y)=\begin{cases}1&y=N\pi,N\in\Bbb Z\\\0&\mbox{otherwise}\end{cases}$.
Now $y=n!\pi x$, so we need $n!x$ to be an integer, $n!x\in\Bbb Z\iff x=\frac \beta{\alpha}$ where both are integers and $\alpha$ divides $n!$(and, ofc, $\alpha\
e0)$, we can notice that if $|\alpha|\le n$ it divides $n!$, taking the limit we have that for every integer $\alpha$.
Thus we left with $$f(x)=\begin{cases}1&x=\frac{\beta}{\alpha},\beta,\alpha_{\
e0}\in\Bbb Z\\\0&\mbox{otherwise}\end{cases}$$
In other words
$$f(x)=\begin{cases}1&x\in\Bbb Q\\\0&\mbox{otherwise}\end{cases}$$