TITLE: How many consecutive composite integers follow k!+1?
QUESTION [8 upvotes]: I wrote a program for myself in Mathematica to generate the answer for the first 300, which was really easy, but I can't find a pattern. The results are here. This is a problem in Underwood Dudley's Elementary Number Theory, but for the LIFE of me I can't figure it out! My initial thought was this: Let m be the smallest prime such that k<m. Then the answer is m-2. This is quite clearly not the answer based on the link I provided. My logic was that any number of the form k!+n will be composite when 1<n<m. That is true. However, it is not the end of the story. Any ideas?
Edit: For anyone curious, this is problem 2 part (b) in section 23.2 of the Second Edition of Underwood Dudley's Elementary Number Theory. Part (a) asks what the smallest integer n is such that n+1, n+2, n+3, and n+4 are all composite.
Second edit: Milcak's comment made me realize that, given some arbitrary n, we can write k!+n=k!+i+j so long as i+j=n. I'm thinking about this now...
Third edit: Here is another problem with the concept for me. I feel like the primes less than or equal to k should help us predict the divisbility of k!+i, and indeed they do, not when i is a prime greater than k. For example, 11!+13=199*200587. That sort of behavior seems unpredictable to me.

REPLY [2 votes]: Bertrand's postulate gives a crude upper bound on $N(k),$ the largest number of consecutive composite numbers following $k!+1.$
For $n>3$ there exists a prime $p$ such that $n<p<2n-2$ and so there is a prime
$$k!+1< p < 2 k!,$$
but the first $(k-1)$ of $k!+2,k!+3, \ldots, 2k!-1$ are certainly composite and so
$$N(k) \le k! - k -1.$$
An additional observation is that if $k! \pm 1$ are not factorial primes then Bertrand's postulate says that there is a prime
$$ k!-k-1 < p < 2k! -2k -4 $$
and so, taking into account Andrea's observation, the first such prime must be $\ge k!+k+1,$ but also $ \le 2k! -2k -5.$ Hence we have for $k>3$
$$N(k) \le (2k!-2k-5)-(k!+2) = k! -2k-7,$$
a slight improvement for the bound in the absence of factorial primes.