First we are going to make some obvious restriction:
$$m \le k \le n$$
Note that if we choose the first number then the following $m-1$ numbers can't be chosen. For example in your example if we choose $2$ to be our first number, then it implies that $3,4,5,6$ are the second, third, fourth and fifth number respectivly.
There are $n-m+1$ to choose the first number, because if we choose a number greater that $n-m$ then we can't choose $m$ consecutive number starting with that one.
Now it's we need to chose $n-m$ random numbers for $k-m$ places.
Because you've mentioned lottery tickets, where the order isn't important we'll assume that in the calculation the order isn't important.
First I want you to note something. I'll again use your example. We take numbers from 1-5 as consecutive and we'll place them in the first 5 places, and then some random number but for the purpose of presentation we'll choose 6. Then the set will be:
$${1,2,3,4,5,6}$$
Now let's think like these, we'll choose the numbers from 2-6 and will place them in the last 5 places and the random number will be 1. The set then will be;
$${1,2,3,4,5,6}$$
Aren't this sets the same? But we choose the using 2 different ways, so that means we'll make some restrictions and we'll make 2 cases.
Case 1: $k=m$
Obviously we have space only to place the consecutive number so let $P(n,k,m)$ represent the number of ways to choose $k$ numbers out of $n$ numbers with $m$ consecutive numbers, so we have:
$$P(n,k,m) = n-m+1$$
Case 2: $k \ge m+1$
Note that if $1$ is the first number of the series we can't choose the predecessor, because there isn't one. So we have:
$$P(n,k,m) = (n-m) \times \binom{n-m-1}{k-m} + \binom{n-m}{k-m}$$
And if we calculate for your example we have:
$$P(49,6,5) = (49-5) \times \binom{49-5-1}{6-5} + \binom{49-5}{6-5}$$
$$P(49,6,5) = 44 \times \binom{43}{1} + \binom{44}{1}$$
$$P(49,6,5) = 44 \times 43 + 44$$
$$P(49,6,5) = 1936$$
Your method will overcount selections such as $\{4,5,6,9,10\}$ because it will arise from $4,5$ or $5,6$ or $9,10$ as the initial pair.
It is simpler first to count all subsets of size $5$, and then subtract the number of such subsets that have no neighboring elements.
The latter count can be found by considering you have to choose some order to put $5$ yes then no
and $5$ no
together. This will give a sequence of $15$ yes
and no
in total, but the last one will always be no
, so it gives you exactly the way of placing $5$ yes
on $\{1,2,3,\ldots,14\}$ such that no two of them are neighbors.
Best Answer
Assuming that the order of choice doesn’t matter, imagine marking the positions of the $r$ chosen numbers and leaving blank spaces before, between, and after them for the $n-r$ non-chosen numbers; if $r=3$, for instance, you’d get a skeleton like $_|_|_|_$, where the vertical bars represent the positions in $1,2,\ldots,n$ of the chosen numbers. The remaining $n-r$ numbers must go into the $r+1$ open slots in the diagram, and there must be at least one of them in each of the $r-1$ slots in the middle. After placing one number in each of those slots, we have $n-r-(r-1)=n-2r+1$ numbers left to place arbitrarily in the $r+1$ slots. This is a standard stars-and-bars problem: there are
$$\binom{(n-2r+1)+(r+1)-1}{(r+1)-1}=\binom{n-r+1}r$$
ways to do it. The reasoning behind the formula is reasonably clearly explained at the link.