Let $p$ be an integer exceeding 1 and suppose $1\leq k\leq p-1.$ Find the number of $k$-element subsets $\{a_1,\cdots, a_k\}$ of $\{1,\cdots, p\}$ so that $a_1+a_2+\cdots + a_k\equiv 0\mod p.$
I've only managed to solve the above problem when p is prime.
If $p=2,$ then the number of 1-element subsets of $\{1,2\}$ with sum congruent to 0 mod 2 is $1.$ Henceforth assume $p>2$. Then note that for every $1\leq k\leq p-1$, we can find a k element subset whose sum is congruent to 0 mod p. Indeed,
- if k is odd and $k=2y+1$ for some $0\leq y\leq p/2 - 1$, we can take the sum $p+(p-1)+1 + \cdots (p-y) + y$ as $p-i, i < p, p-i\neq i$ for $i < p$, $p-y > y$ since $y < p/2,$ and $y$ is the highest second element among the pairs $(p-1,1),(p-2,2),\cdots, (p-y,y)$ while the first terms are strictly decreasing.
- If $k=2y$ is even, then we have the sum $(p-1 + 1) + \cdots + (p-y+y),$ which is a sum of distinct elements by similar reasoning to above as $y \leq (p-1)/2.$
Now given such a subset, say $B := \{a_1,\cdots, a_k\},$ define for $0\leq i\leq p-1$ the subset $B_i$ by $$B_i := \{f(a_1+i), \cdots, f(a_k+i)\}$$ where $f(x)$ is the unique element $y$ of $\{1,\cdots, p\}$ so that $x\equiv y\mod p.$
Then note that all the elements $a_j + i$ are distinct modulo $p$ and since $f(a_j+i)\equiv a_j+i\bmod p$ for all $a_j+i$, the terms $f(b)$ are distinct where $b$ ranges over $B.$
Also, $\sum_{a\in B_i} a \equiv a_1+\cdots + a_k + ik \equiv ik\mod p.$ Each residue $ik\mod p$ is distinct because if $ik \equiv jk$ for some $0\leq i < j < p,$ then $p$ would divide $(i-j)k$ and hence $p$ would divide $(i-j)$. Since $p$ is coprime to $k$, this implies $i-j$ is divisible by $p$, which is a contradiction since $0<|i-j|<p.$ Hence each $B_i$ is distinct.
Now note that each $k$-subset of $\{1,\cdots, p\}$ belongs to exactly one $B_i, 0\leq i\leq p-1$ for some $B$. Indeed, let for each $B,$ the set of $B_i$'s defined above be the cycle of B. Note that if two cycles intersected, then they would be the same cycle. Note that here it's crucial that $p$ is prime (the claims above could still work if $p$ was replaced by $\dfrac{p}{\gcd(p,k)}$). Suppose the cycles of $B=\{b_1,\cdots, b_k\}$ and $A=\{a_1,\cdots, a_k\}$ intersected. Then there exist $s,t$ so that $A_t = B_s$. So $a_i + t \equiv b_{\sigma(i)} + s$ for some permutation $\sigma$ of $\{1,\cdots, k\}.$ Then $a_i\equiv b_{\sigma(i)} + s-t$ for all i. But then A equals $B_{s-t}$ ($B_{s-t}$ may not be defined if we replaced $p$ with $\dfrac{p}{\gcd(p,k)}$ in our construction of the $B_i$'s). Hence for all $0\leq i\leq p-1, A_i$ equals $B_{s-t + i\mod p}$ and since the cycle elements $B_i$ are distinct for all i, this shows that the map $A_i\mapsto B_{(s-t+i)\mod p}$ defines a bijection between the cycle of A and the cycle of B. Hence distinct cycles are disjoint. But in each cycle, each of the $B_i$'s has a distinct sum modulo p as proved above, so exactly one $B_i$ has sum $0$ mod p.
Thus, the required answer is $\dfrac{{p\choose k}}{p}.$
I'm not sure if generating functions could be useful when p is not prime. Let $\xi$ be a primitive p-th root of unity (note that these are precisely the numbers of the form $e^{2\pi i k/p}$ where k is coprime to p).
Consider the product $\prod_{j=1}^p (1+\xi^j).$ Note that when this product is written in the form $b_1 \xi + b_2\xi^2+\cdots + b_p \xi^p$ (which is possible since $\xi^p=1\Rightarrow \xi^{p+k} = \xi^k$ for all k), $b_p$ equals the number of subsets of $x$ with sum divisible by p.