# number of solutions to the equation $x_1+x_2+x_3=2018$ with odd\even condition on $x$.

I have to find the number of solutions to $x_1+x_2+x_3=2018$ ,

with the following conditions :

1. $x_1,x_2,x_3$ are even numbers.
2. $x_1$ is even while $x_2$ and $x_3$ are odd.

I guess I have to use stars and bars in order to solve it, so in case one I reffed to every two stars as one star and then solved this equation $x_1+x_2+x_3=1009$ (with stars and bars again). but in case two i'm stuck, I don't understand how to divide the stars correctly when odd and even conditions are involved.

appreciate your help very much!

In the second case you can write $x_1=2k, x_2=2m+1, x_3=2n+1.$ Then $$2018=x_1+x_2+x_3=2k+2m+1+2n+1,$$ what gives "stars and bars" for equation $1008=k+m+n$.

Ps. Always specify the domains for $x$'s - are they positive, non-negative or arbitrary integers? All these three variants of "stars and bars" have different solutions.

• @drhab Thank you! – Paweł Czyż Apr 14 '18 at 17:25

Use generating functions to solve the the second question. Indeed,we seek the coefficient of $x^{2018}$ in the series expansion of $$(x^0+x^2+x^4+\dotsb)(x+x^3+x^5+\dotsb)^2=\frac{1}{1-x^2}\times\frac{x^2}{(1-x^2)^2}=\frac{x^2}{(1-x^2)^3}$$ Thus we seek the coefficient of $x^{2016}$ in the series expansion of $$(1-x^2)^{-3}=\sum_{n=0}^\infty\binom{n+2}{2}x^{2n}$$ Hence the number of solutions is $$\binom{1008+2}{2}=\binom{1010}{2}.$$

Hint: Even numbers can be uniquely written in the form $2k$ and odd numbers can be uniquely written in the form $2k+1$ for some integer $k$.

Indeed stars and bars, and your idea about 1) is okay.

Hint on 2):

Find the number of solutions of $y_1+y_2+y_3=1008$.

If $(y_1,y_2,y_3)$ is such a solution then $(2y_1,2y_2+1,2y_2+1)$ will satisfy the conditions under 2).

How many solutions are there for $x_2+x_3=2n$ with both $x_2$ and $x_3$ odd? Well, $x_2$ can range from $1$ to $2n-1$, so there are $n$ solutions. This means that, for a given $x_1=2k$, your equation $x_1+x_2+x_3=2018$ has $\frac{2018-x_1}{2}=1009-k$ solutions. Since $k$ may take values from $0$ to $1009$, the total number of solutions is $$\sum_{k=0}^{1009}{(1009-k)}=\sum_{k=0}^{1009}{k}=\frac{1009\times1010}{2}=509545.$$