I stumbled on a claim on the internet the other day, which alleged that the following formula tests the primality for integers $n\geq2$: $$ \left\lceil\left|\left\{\frac{\left(n+\left\lceil\frac{n}{2}\right\rceil\right)!}{n!n\left\lceil\frac{n}{2}\right\rceil !}\right\}-\frac{1}{n}\right|\right\rceil =\begin{cases} 0,\quad \text{if }n\text{ is prime} \\ 1,\quad \text{if }n\text{ is composite} \end{cases} $$ where $|\cdot|$ is absoulte value, $\lceil\cdot\rceil$ is ceiling function and $\{\cdot\}$ denotes the fractional part.
I test it in Mathematica for $2\leq n\leq5000$ and it seems correct in this range. Code below:
ClearAll["Global`*"]
f[n_]:=Ceiling[Abs[FractionalPart[(n+Ceiling[n/2])!/(n!n(Ceiling[n/2])!)]-1/n]];
For[i=2,i<=5000,i++,
If[((f[i]==0&&PrimeQ[i]==True)||(f[i]==1&&PrimeQ[i]==False))==False,Print[i," is false"]];
]
Since the formula involves factorial $n!$, its computational efficiency could not be very high. Nonetheless, I have following questions:
- Could this formula be valid for the primality test of all $n\geq2$?
- If it is a valid formula, does anyone know where this formula comes from?