8

For every $n\geq 1$, $n!+1$ and $(n+1)!+1$ are coprime. I suspected the same would happen for $n!+1$ and $(n+2)!+1$, but short Python script yielded 3 counterexamples:

  • $\gcd(7!+1,9!+1)=71$
  • $\gcd(16!+1,18!+1)=61$
  • $\gcd(61!+1,63!+1)=71$

But up to $n=30000$ it finds no more counterexamples.

So it could be that $7$, $16$ and $61$ are the only ones or that Python is hallucinating (does it really handle numbers as large as $30000!$?).

Which is it?


Edit: as discussed in the comment section, $$\gcd(n!+1,(n+2)!+1) = \gcd(n!+1,n^2+3n+1).$$ So considering $n^2+3n+1$ instead of $(n+2)!+1$ might simplify the problem.

  • Comments have been moved to chat; please do not continue the discussion here. Before posting a comment below this one, please review the purposes of comments. Comments that do not request clarification or suggest improvements usually belong as an answer, on [meta], or in [chat]. Comments continuing discussion may be removed. – Xander Henderson Dec 27 '23 at 14:23

1 Answers1

7

As to the mathematical question: we are looking for $n$ such that $n! + 1$ and $n^2 + 3n + 1$ are both divisible by an odd prime $p$. Of course $p > n$. The roots of $x^2 + 3x + 1$ are $(-3 \pm \sqrt{5})/2$, so $5$ must be a square mod $p$, which says (if $p > 5$) $p \equiv 1$ or $4 \mod 5$. These are asymptotically about half of all primes. For such $p$, there are two values of $n \in [0, \ldots,p-1]$ which make $n^2 + 3n + 1$ divisible by $p$.

Heuristically the probability that $n!+1$ is also divisible by $p$ is about $1/p$. So since the sum of $1/p$ for primes $p$ diverges, we should expect there to be infinitely many counterexamples. However, since the sum diverges very slowly, it may be very difficult to find more of those counterexamples.

Robert Israel
  • 448,999