Show that $p$ is prime if the following limit property holds Let $n$ be a positive integer. Show that $n$ is prime if and only if
$$\lim_{r\to \infty}\lim_{s\to\infty} \lim_{t\to\infty} \sum_{k=0}^s\left(1-\left(\cos\left(\frac{(k!)^r\pi}{n}\right)\right)^2t\right)=n$$
 A: I'm assuming that $t$ is intended to be in the exponent, and that the limits are intended to be taken over the integers.
In that case, notice that $\lim_{t\to\infty} (\cos \theta)^{2t}$ is zero unless $\theta$ is a multiple of $\pi$, in which case the limit is 1. The sum therefore counts how for how many values of $k$ the integer $(k!)^r$ is not divisible by $n$.
Clearly $(k!)^r$ is divisible by $n$ when $k\geq n$, so we can ignore the limit in $s$ and replace it with 
$$\lim_{r\to\infty}\lim_{t\to\infty} \sum_{k=0}^{n-1} \left(1-\cos\left[(k!)^r\pi/n\right]^{2t}\right).$$
Suppose $n$ is prime. Then $n$ does not divide $k!$, and does not divide $(k!)^r$, for any $k=0,\ldots,n-1$, so the above expression is $n$.
Now suppose $n$ is composite. Then you can write $n=ab$ where $a$ is the least nontrivial divisor of $n$. There are two cases: $a=b$ (and $n$ is the square of a prime) or $a<b$.
In the former case, $n\vert (a!)^2$ and so the above sum, and hence the limit, evaluates to an integer strictly less than $n$ for $r\geq 2$. In the latter case, $n\vert b!$ and the limit evaluates to an integer strictly less than $n$.
