The set $S=\{a+1,a+2, a+3,\dots,a+2015,a+2016\}$ with exactly 20 primes Consider a set $S=\{a+1,a+2, a+3,\dots,a+2015,a+2016\}$, where $a$ is a positive integer.
The question is to prove that there exists a number $a$ such that the set contains exactly $20$ primes.
I already know that, denoting $a=2016!+1$, the set $S$ is left with no primes. And if $a=0$ there exists more than $20$ primes. So by intuition somewhere between $0<a<2016!+1$ there is a number $a$ that does the trick.
Is there deeper or more formal way to prove this, or even find an exact value for $a$?
Thanks for your answers.
 A: You have the right idea.

Just keep incrementing $a$, starting with $a=1$.

Given a value of $a$, then in the next step


*

*If $a+1$ is prime, you will lose that prime.$\\[2pt]$

*If $a+2017$ is prime, you will gain that prime.



It follows that in one step, you can never lose more than one prime, or gain more than one prime. Thus, at each step, the number of primes either doesn't change, or changes by exactly one, either $1$ up, or $1$ down.

Since the count starts out more than $20$ and, as you noted, the count reaches zero for some value $a$, then for some $a$ along the way, the count must be exactly $20$.

For a more formal justification of this last claim, we can invoke the well-ordering principle . . .

For $a \in \mathbb{Z}^{+}$, let $f(a)$ be the number of primes in the set
$\{a+1,...,a+2016\}$.

The goal is to show that $f(a)=20$, for some $a \in \mathbb{Z}^{+}$.

Let $S = \{a  \in \mathbb{Z}^{+} \mid f(a) \le 20\}$.

We know $f(a) = 0$ for some positive integer $a$, so $S$ is nonempty, hence by the well-ordering principle, $S$ has a least element, $b$ say.

Since $b \in S$, we have $f(b) \le 20$.

Claim $f(b)=20$.

We know $1 \notin S$, so $b > 1$.

By choice of $b$, we must have $f(b-1) > 20$, hence $f(b-1) \ge 21$.

But we know that in the transition from $a=b-1$ to $a=b$, the number of primes can't go down by more than $1$, hence
\begin{align*}
&f(b) \ge f(b-1)-1\\[4pt]
\implies\;&f(b) \ge 20\\[4pt]
\implies\;&20 \le f(b) \le 20\\[4pt]
\implies\;&f(b) = 20\\[4pt]
&\text{as claimed.}\\[4pt]
\end{align*} 
