Combinatorics – Find Subsets of $\{1, 2, \ldots,2015\}$ with Sum Divisible by 5

combinatoricscontest-mathgenerating-functions

The problem is as in the question title. Only one addition – $n$ is not divisible by $5$.

I already have a solution involving permutations, but recently I read about generating functions and I was wondering if this problem can be solved with them.

A similar problem is the following:
Find the number of all subsets of $\{1, 2, \ldots, 2015\}$ and the sum of elements in each subset is divisible by 5. The generating function used is $${((1+x^0)(1+x^1)(1+x^2)(1+x^3)(1+x^4))}^{403}.$$

But this function cannot be used for my problem, since we need to count how many elements have been "used" to make the subset. Can anyone help me?

Best Answer

A generating function solution.

For every $S\subset\{1,2,\ldots,2015\}$ we will write $\Sigma S=\sum_{k\in S}k$.

Let $$ f(a,x) = \prod_{k=1}^{2015} (1+a^kx) = \sum_{S\subset\{1,\ldots,2015\}} a^{\Sigma S} x^{|S|}. $$ Take the average this function over putting $5$th complex roots of unity for $a$. Let $\omega=e^{2\pi i/5}$; then $$ \frac15\sum_{j=0}^4 f(\omega^j,x) = \sum_{S\subset\{1,\ldots,2015\}} \left(\frac15\sum_{j=0}^4 \big(\omega^{\Sigma S}\big)^j\right) x^{|S|} = \sum_{\substack{S\subset\{1,\ldots,2015\}\\\Sigma S\equiv0\pmod5}} x^{|S|}. \tag{$*$} $$ On the RHS of $(*)$, the coefficient of $x^n$ is the number of $n$-element sets $S\subset\{1,\ldots,2015\}$ with $\Sigma S\equiv0\pmod5$.

On the other hand, $$ f(\omega^j,x)= \begin{cases} (1+x)^{2015} & \text{if } j=0 \\ (1+x^5)^{403} & \text{if } j=1,2,3,4 \end{cases} $$ so on the LHS of $(*)$ the coefficient of $x^n$ is: $\frac15\binom{2015}n$ if $n$ is co-prime with $5$, and $\frac15\binom{2015}n+\frac45\binom{403}{n/5}$ if $5|n$.