Count the number of selecting 5 numbers I would appreciate if somebody could help me with the following problem:
Q: Count the number of selecting 5 numbers in 
$\{1, 2, 3, ... n\} (n>5)$, excepting the choice of consecutive three numbers.
(i.e.the section does not contain consecutive three numbers.)
For example, $\{1, 2, 4, 5, 7\}$ is valid but 
$\{1, 2, 4, 5, 6\}$ is not valid.

You can use an inclusion-exclusion argument. There are $\binom{n}5$ ways to select $5$ numbers from $[n]=\{1,\dots,n\}$. Picking a set of $5$ that includes $3$ adjacent numbers is like picking $3$ numbers from $[n-2]$: you can treat the block of $3$ as a single number. There are $\binom{n-2}3$ ways to do that, but the block could be any of the $3$ ‘numbers’ chosen, so there are actually $3\binom{n-2}3$ sets of $5$ that include a run of $3$ consecutive numbers. This brings the total number of acceptable choices down to
$$\binom{n}5-3\binom{n-2}3\;.\tag{1}$$
Unfortunately, the correction term in $(1)$ overcounts: a set like $\{1,2,3,4,6\}$, with a run of $4$, is subtracted twice, once with $\{1,2,3\}$ treated as a run and once with $\{2,3,4\}$, and needs to be added back in. Argue as before: treat the run of $4$ as a single ‘number’, so that you’re selecting two ‘numbers’ from $[n-3]$, either of which can be the run, for a total of $2\binom{n-3}2$ sets to be added back in to get
$$\binom{n}5-3\binom{n-2}3+2\binom{n-3}2\;.\tag{2}$$
Finally, $(2)$ counts each run of $5$ in the first term, subtracts it $3$ times in the second term, and adds it back in twice in the third term, for a net count of $0$. Since this is what we want, $(2)$ needs no further correction.
As a quick and dirty check, $(2)$ correctly gives $0$ for $n=6$ and $3$ for $n=7$, those $3$ being $\{1,2,4,5,7\},\{1,2,4,6,7\}$, and $\{1,3,4,6,7\}$.
