Let $k$ be a integer such that $k\ge2$
Why does $$(k-2)!-k \left\lfloor \frac{k!}{(k-1) k^2}\right\rfloor = 1$$ only when $k$ is prime?
Example:
$$\pi(n) = \sum _{k=4}^n \left((k-2)!-k \left\lfloor \frac{k!}{(k-1) k^2}\right\rfloor \right),\;n\ge4$$
where $k=4,$ since:
$$\pi(4)\quad=\quad(4-2)!-4 \left\lfloor \frac{4!}{(4-1) 4^2}\right\rfloor = 2$$
I've tried to evaluate it in different forms, and I am probably just overlooking something obvious; So if anyone has any information in regard to this, please share.
If $k$ is not a prime, then the equation is $0$ modulo $k$. (We have $(k-2)! \equiv 0 \pmod{k}$.)
Conversely if $k$ is a prime, then by Wilson's theorem $(k-2)! \equiv 1 \pmod{k}$.
Edit: (To complete the argument.) If $k$ is a prime, then $(k-2)! = 1 + l k$ for some $l \ge 0$. Equivalently $l = \frac{(k-2)! - 1}{k}$ and we must show that $l = \left\lfloor \frac{k!}{(k-1)k^2} \right\rfloor$. But this is true since
$$\left\lfloor \frac{k!}{(k-1)k^2} \right\rfloor = \left\lfloor \frac{(k-2)!}{k} \right\rfloor$$ and the greatest number below $(k-2)!$ that is divisible by $k$ is $(k-2)! - 1$.