Counting the lottery tickets with repeatable numbers. Here's the question I'm trying to solve:

In a certain lottery, players must choose 6 numbers from the set {1, 2, 3, . . . , 40}. Suppose that a player can choose any number as many times (up to 6 total) as they wish. For example, a player might choose {1, 2, 2, 3, 38, 39}. How many distinct lottery tickets are possible?

I thought I could just treat the questions as 6 independent events and everytime I have 40 choices so there are $40^6$ ways in total. However, the solution says we need 39
dividers to create 40 bins and we have 6 beans to distribute. So there are $C_{45}^6$ ways in total. I don't quite understand what that means. Why my first thought is wrong? Thanks!
 A: If the ticket consisted of an ordered sequence of six numbers, your answer would be correct since there would be $40$ choices for each of the six entries.
In this case, the tickets are distinguished by how often each number appears on the ticket.  Therefore, we seek the number of solutions of the equation
$$x_1 + x_2 + x_3 + \cdots + x_{38} + x_{39} + x_{40} = 6 \tag{1}$$
where $x_i$, $1 \leq i \leq 40$, is the number of times the number $i$ appears on the ticket.  A particular solution of this equation corresponds to the placement of $40 - 1 = 39$ addition signs in a row of $6$ ones.  For instance,
$$1 + 1 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 1 +$$
represents the ticket $1, 2, 2, 3, 38, 39$.  The number of tickets is the number of solutions of equation 1 in the nonnegative integers, which is
$$\binom{6 + 40 - 1}{40 - 1} = \binom{45}{39}$$
since we must select which $39$ of the $45$ positions required for $6$ ones and $39$ addition signs will be filled with addition signs.
