Problem in elementary number theory about prime numbers. I was looking at a packet of problems in elementary number theory, when I saw this question: 
Show that $n$ is prime iff 
$$\lim_{r\rightarrow\infty}\,\lim_{s\rightarrow\infty}\,\lim_{t\rightarrow\infty}\,\sum_{u=0}^{s}\left(1-\left(\cos\,\frac{(u!)^{r}\pi}{n}\right)^{2t}\right)=n $$
How would one solve this problem?
 A: First note that:
$$\lim_{t\rightarrow\infty}\left(\cos\,\frac{(u!)^{r}\pi}{n}\right)^{2t}=\chi_{\mathbb Z}\left(\frac{(u!)^{r}}{n}\right)=
\begin{cases}
1&\text{if $\frac{(u!)^{r}}{n}\in\mathbb Z$}\\
0&\text{otherwise}\\
\end{cases}$$
thus
$$\lim_{t\rightarrow+\infty}\,\sum_{u=0}^{s}\left(1-\left(\cos\,\frac{(u!)^{r}\pi}{n}\right)^{2t}\right)=\sharp\{u\in\{0,\ldots,s\} : (u!)^{r}\notin n\mathbb Z\}$$
$$\lim_{s\to+\infty}\lim_{t\rightarrow+\infty}\,\sum_{u=0}^{s}\left(1-\left(\cos\,\frac{(u!)^{r}\pi}{n}\right)^{2t}\right)=\sharp\{u\in\mathbb N : (u!)^{r}\notin n\mathbb Z\}$$
Assuming $r$ to be a positive integer, we have:
$$\lim_{s\to+\infty}\lim_{t\rightarrow+\infty}\,\sum_{u=0}^{s}\left(1-\left(\cos\,\frac{(u!)^{r}\pi}{n}\right)^{2t}\right)=\sharp\{u\in\mathbb N : n\nmid (u!)^{r}\}$$.
For large $r$, we have $n\nmid (u!)^r$ if and only if there exists a prime $p$ such that $p\mid n$ and $p\nmid u!$. More over, $p\nmid u!$ if and only if $u<p$.
\begin{align}
\lim_{r\to+\infty}\lim_{s\to+\infty}\lim_{t\rightarrow+\infty}\,\sum_{u=0}^{s}\left(1-\left(\cos\,\frac{(u!)^{r}\pi}{n}\right)^{2t}\right)=
&\sharp\{u\in\mathbb N : \exists p\text{ prime }(p\mid n\wedge u<p)\}\\
&=\max\{p\text{ prime }:p\mid n\}
\end{align}
Clearly, $\max\{p\text{ prime }:p\mid n\}=n$ if and only if $n$ is prime.
