# Conjecture about primes and the factorial: for all primes $p>5$, must there exist a prime $q<p$ such that $q\equiv m!\pmod p$ for some $2<m<p$?

Below $0\notin\mathbb N$.
Further corrected conjecture:

For all prime numbers $p>5$ there exist a prime number $q<p$ such that $q\equiv m!\!\pmod p$, $2<m<p$.

or

Given a prime $p>5$ there exist a prime $q<p$ and $k,m\in\mathbb N$, $2<m<p$, such that $kp+q=m!$

I want help to prove the conjecture (which is tested for all $p<100,000,000$) or to find a counter-example.

p=7  q=3  k=3   m=4
p=11 q=2  k=2   m=4
p=13 q=11 k=1   m=4
p=17 q=7  k=1   m=4
p=19 q=5  k=1   m=4
p=23 q=5  k=5   m=5
p=29 q=23 k=173 m=7
p=31 q=7  k=23  m=6
p=37 q=17 k=19  m=6
p=41 q=23 k=17  m=6
p=43 q=29 k=937 m=8
p=47 q=11 k=107 m=7
p=53 q=31 k=13  m=6
p=59 q=2  k=2   m=5
p=61 q=59 k=1   m=5
p=67 q=53 k=1   m=5 ...


Up to the prime 1020361

For several reasons I have had major problems extracting my real observations.

Also, the primes are not unique having this property, a lot of semiprimes, but not all, and occasionally some other numbers, also have it. It seems like less than one third of all natural numbers have it and there is a secondary conjecture:

For all primes $p$ there is a prime $q<p^2$ such that $q\equiv m!\pmod {p^2}$, $2<m<p^2$.

tested for all $p<100,000,000$.

There are strong reasons to believe that the conjecture is true. Suppose $0\equiv m!\!\pmod n$, then $0\equiv r!\!\pmod n$ for all $r>m$. And suppose $n=sp^t$, where $p$ is the largest prime dividing $n$, $p\nmid s$ and $t>0$, then $0\equiv (pt)!\!\pmod n$. If $p$ is a large prime there are a lot of nonzero solutions to $x\equiv m!\!\pmod p$ and the probability for one of those solutions to be a prime increase with p.

• When $p=3$, if $m\ge3$, then $q$ must be divisible by $3$, so $q$ has to be $3$, which violates $q<p$. If $m<3$, then $m!<p$, so $k$ has to be zero, which violates $k\in\mathbb Z_+$. Jun 25, 2016 at 6:23
• The reason why I think this is likely true is that there are so many distinct residue classes of factorials modulo a prime $p$. I did a quick test for the 200 smallest primes, and it suggests that something like 63% of the residue classes are congruent to some factorial. Therefore it is very likely that we have hits with some of the smaller primes. The small primes seem to be the high risk cases, and they have adequately tested. I admit that this is not even a heuristic argument in favor of your conjecture, but somebody who's been there before may be able to turn it into one. Jul 18, 2016 at 19:55

For $p=3$, $q$ has to be $2$.
Suppose that there exist $k,m\in\mathbb Z$ such that $$3k+2=m!$$ Since $m\gt 2$, the RHS is divisible by $3$. This is a contradiction.
Added : Similarly, for $p=5$, there is no such prime $q$.
• Thanks! It's very hot in Sweden right now $\overset{..}{\smile}$.