# $n_{p,k} = \frac{1}{p}\binom{p}{k}$ for counting $k$-element subsets of $\left\{1,2,\ldots,p\right\}$ with sum divisible by $p$

Let $$p$$ be prime and $$k$$ be an integer where $$0.

Let $$n_{p,k}$$ denote the number of subsets $$S$$ of $$\{1, 2, ..., p\}$$ such that $$\left|S\right| = k$$ and such that the sum of all the elements in $$S$$ is divisible by $$p$$.

Show that $$n_{p,k} = \dfrac{1}{p}\dbinom{p}{k}$$.

Attempted work :

Let $$l$$ be positive integer such that $$kl \equiv 1\; (\bmod p)$$

and $$\{a_1, a_2, ..., a_k\} \in \mathcal F_a(p,k)$$

Let $$f_{a,b} : \mathcal F_a(p,k) \to \mathcal F_b(p,k)$$ defined by

$$f(\{a_1, a_2, ..., a_k\}) = \{b_1, b_2, ..., b_k\}$$ , where

$$a_1 + l(a-b) \equiv b_1\; (\bmod p)\;\;, \; 0\leq b_1

$$a_2 + l(a-b) \equiv b_2\; (\bmod p)\;\;, \; 0\leq b_2

.

.

$$a_k + l(a-b) \equiv b_k\; (\bmod p)\;\;, \; 0\leq b_k

1) To show that $$f$$ is injective

Let $$f(\{a_1, a_2, ..., a_k\}) = f(\{a'_1, a'_2, ..., a'_k\})$$

so $$\{b_1, b_2, ..., b_k\} = f(\{a'_1, a'_2, ..., a'_k\})$$

we obtain $$a'_i + l(a-b) \equiv b_i\; (\bmod p)$$

and $$a'_i \equiv a_i\; (\bmod p)$$

so $$a'_i = a_i , \;\forall i = 1, 2, ..., p$$, thus $$f$$ is injective.

2) To prove that $$f$$ is surjective

Let $$\{b_1, b_2, ..., b_k\} \in \mathcal F_b(p,k)$$

Choose

$$a_1 \equiv b_1- l(a-b) \; (\bmod p)$$

$$a_2 \equiv b_2- l(a-b) \; (\bmod p)$$

.

.

$$a_k \equiv b_k- l(a-b) \; (\bmod p)$$ , where $$gcd(l,p) = 1$$

so, $$f(\{a_1,\dots,a_k\}) = \{b_1, \dots, b_k\}$$, thus $$f$$ is surjective.

Therefore $$f$$ is bijective, $$|\mathcal F_a(p,k)|= |\mathcal F_b(p,k)|\;\forall a, b$$ so $$|\mathcal F_0(p,k)|= \frac{1}{p}\binom{p}{k}$$.

• It would be true that the expected number of ways to choose the next element is ${\binom{p}{k+1}}/{\binom{p}{k}}$ (which is not integer for most cases), but how one could show this? – didgogns Apr 1 '17 at 15:06
• @didgogns, thank you for pointing out my mistake.${\binom{p}{k+1}}/{\binom{p}{k}}=\frac{p-k}{k+1}$, which may not be integer. Can someone please suggest on how to solve this problem ? – carat Apr 1 '17 at 15:46

Let $$X_k$$ be the set of $$k$$-element subsets of $$\{1,2,\ldots,p\}$$. Let the cyclic group $$G=\mathbf{Z}/p\mathbf{Z}$$ act on $$X_k$$ by translation: that is, for $$a\in G$$, we define $$\sigma_a(\{x_1,\dots, x_k\}) = \{x_1+a,\ldots,x_k+a\}$$ where addition is mod $$p$$. This makes sense since translation preserves distinctness.

So far this makes sense for any $$p$$. But when $$p$$ is prime, this action is free: that is, if $$a\ne0$$, there is no $$k$$-tuple mapped to itself by $$\sigma_a$$. A cute way to see this is to look at the (mod $$p$$) sum of the elements of a subset. If we apply $$\sigma_a$$ to a subset whose sum is $$s$$, the sum of the resulting elements is $$s+ak$$ (mod $$p$$). If the subset is fixed by $$\sigma_a$$, then $$s+ak=s$$ (mod $$p$$), so $$ak=0$$ (mod $$p$$). But $$k$$ is not divisible by $$p$$, hence (since $$p$$ is prime) $$a=0$$ (mod $$p$$), and we see the action is free.

So each orbit of the action has size $$p$$ (hence $$\binom pk$$ is divisible by $$p$$) and furthermore each possible sum appears exactly once in each orbit, for a total of $$\frac1p\binom pk$$ times each.

(Added in response to OP comment:)

At a high school level, and expressed without group theory, we are arguing that when $$p$$ is prime, the following group of $$p$$ subsets $$\begin{array}{lcl} \{x_1,&\dots,&x_k\}\\ \{x_1+1,&\ldots,&x_k+1\} \mod p\\ \vdots&\vdots&\vdots\\ \{x_1+p-1,&\ldots,&x_k+p-1\} \mod p \end{array}$$ all have different sums mod $$p$$, so each possible sum appears exactly once. (This also means the subsets in the group are actually different.) As $$X_k$$ is the disjoint union of groups of this kind, that means the possible sums occur equally often as you look across $$X_k$$.

If you're in high school, there are a few details to fill in, so you should do that. But the other thing to do would be to learn some basic group theory, which is accessible to any high school student (some experience with proofs helps, but group theory is as good as geometry for studying mathematical argument anyway). Once you check that what you have is a group acting freely on a set, a lot of those details come for free, and the structure of the argument becomes much more transparent.

• Thank you, Tad. Could you please provide elementary solution, at high school level ? – carat Apr 2 '17 at 6:08
• Thank you for your helpful advice, Tad. Will you please suggest me books or articles on basic group theory that high school student should know and not too hard to understand ? – carat Apr 3 '17 at 5:03
• Start here: math.stackexchange.com/q/2151540/85024 – Tad Apr 3 '17 at 11:45

This is not a complete answer, but an idea or two for how to approach the problem.

It is more broadly true that for any remainder $0 \le r < p$, the number of subsets $S$ of size $k$ whose sum is congruent to $r$ modulo $p$ is $\frac1p \binom{p}{k}$. In other words, taking the sum modulo $p$ divides the subsets of size $k$ into $p$ equal parts.

For convenience, let's define $\mathcal F_r(p,k)$ or just $\mathcal F_r$ to be the collection of all subsets of $\{1,2,\dots,p\}$ of size $k$, whose sum is congruent to $r$ modulo $p$. So you're looking for $n_{p,k} = |\mathcal F_0(p,k)|$, and I claim that $$|\mathcal F_0(p,k)| = |\mathcal F_1(p,k)| = \dots = |\mathcal F_{p-1}(p,k)|.$$ Since the total size of these $p$ collections is $\binom{p}{k}$, if we can prove that they all have equal size, then we can conclude that each has size $\frac1p \binom pk$.

For example, if $p=5$ and $k=3$, we have: \begin{align} \mathcal F_0 &= \{\{1,4,5\}, \{2,3,5\}\} & 1+4+5 &\equiv 2+3+5 \equiv 0 \pmod 5 \\ \mathcal F_1 &= \{\{1,2,3\}, \{2,4,5\}\} & 1+2+3 &\equiv 2+4+5 \equiv 1 \pmod 5 \\ \mathcal F_2 &= \{\{1,2,4\}, \{3,4,5\}\} & 1+2+4 &\equiv 3+4+5 \equiv 2 \pmod 5 \\ \mathcal F_3 &= \{\{1,2,5\}, \{1,3,4\}\} & 1+2+5 &\equiv 1+3+4 \equiv 3 \pmod 5 \\ \mathcal F_4 &= \{\{1,3,5\}, \{2,3,4\}\} & 1+3+5 &\equiv 2+3+4 \equiv 4 \pmod 5 \end{align} so all $\binom{5}{3}=10$ subsets of size $3$ are partitioned into $5$ groups of size $\frac15 \binom{5}{3} = 2$ by looking at their sum modulo $5$.

Since $\frac1p \binom pk$ is a rather ugly number, proving that $|\mathcal F_r(p,k)|$ is exactly $\frac1p \binom pk$ is hard. On the other hand, proving that $|\mathcal F_r(p,k)| = |\mathcal F_s(p,k)|$ is easier:

• A standard way to do it is to find a bijection $f_{r,s} : \mathcal F_r(p,k) \to \mathcal F_s(p,k)$. In other words, if we pair up the elements of $\mathcal F_r$ and the elements of $\mathcal F_s$, then we know that $|\mathcal F_r| = |\mathcal F_s|$. In this problem, you could proceed by showing how to pair up the elements of $\mathcal F_r$ and the elements of $\mathcal F_s$ for any $r \ne s$.
• Another way is to break all $\binom{p}{k}$ subsets into groups of size $p$ somehow, such that every group has exactly one element from $\mathcal F_0$, one element from $\mathcal F_1$, and so on. Since each group is evenly split between the $\mathcal F_r$ collections, all the groups combined must be evenly split.
• Thank you, Misha. Please see my work above. Is my understanding correct ? And I still don't know how to prove that $f$ is surjective. – carat Apr 2 '17 at 6:00
• You could show $f$ surjective by finding a formula for a set $\{a_1, \dots, a_k\}$ which maps to $\{b_1, \dots, b_k\}$. But in your case, it might be easier to check that $f_{a,b}$ and $f_{b,a}$ are inverses: a function that has an inverse is always a bijection. – Misha Lavrov Apr 2 '17 at 6:03
• Also, I'm sure you realize this or you wouldn't have chosen $l$ the way you did, but an important part of the proof is checking that for any $S \in \mathcal F_a$, we do actually get $f_{a,b}(S) \in \mathcal F_b$. – Misha Lavrov Apr 2 '17 at 6:04
• Please check my work if it's correct or not. Thanks. – carat Apr 2 '17 at 7:43
• To prove $f$ is surjective, you shouldn't be choosing $l$; that's fixed when you define $f$. "Choose $a_1, a_2, \dots, a_k$ such that ...." would technically make that sentence correct, but not a very good explanation: it's better to say: "Choose $a_1 = b_1 - l(a-b) \bmod p$" and so on, then explain that this makes $f(\{a_1,\dots,a_k\}) = \{b_1, \dots, b_k\}$. – Misha Lavrov Apr 2 '17 at 14:40

Using the Polya Enumeration Theorem we deploy the unlabled set operator $\mathfrak{P}$ and get for the generating function

$$Z(P_k)(z+z^2+\cdots+z^p)$$

for a closed form of

$$\frac{1}{p} \sum_{r=0}^{p-1} \left. Z(P_k)(z+z^2+\cdots+z^p) \right|_{z=\zeta_p^r}$$

where $\zeta_p = \exp(2\pi i/p).$ The exponential formula tells us the OGF of the cycle index for the set operator $Z(P_k)$ which is

$$Z(P_k) = [w^k] \exp\left(\sum_{l\ge 1} (-1)^{l-1} a_l \frac{w^l}{l}\right)$$

Doing the substitution we find

$$[w^k] \frac{1}{p} \sum_{r=0}^{p-1} \left. \exp\left(\sum_{l\ge 1} (-1)^{l-1} \left(\sum_{q=1}^p z^{ql} \right) \frac{w^l}{l}\right) \right|_{z=\zeta_p^r} \\ = [w^k] \frac{1}{p} \sum_{r=0}^{p-1} \exp\left(\sum_{l\ge 1} (-1)^{l-1} \left(\sum_{q=1}^p (\zeta_p^{rl})^{q} \right) \frac{w^l}{l}\right).$$

With $p$ prime the innermost sum of powers of $\zeta_p$ is $p$ if $p|rl$ and zero otherwise. We thus have two contributions, the first of which originates with $r=0$ and yields

$$[w^k] \frac{1}{p} \exp\left(p \sum_{l\ge 1} (-1)^{l-1} \frac{w^l}{l}\right) \\ = [w^k] \frac{1}{p} \exp\left(p \log(1+w)\right) \\ = [w^k] \frac{1}{p} (1+w)^p = \frac{1}{p} {p\choose k}.$$

This is the target value. We are done if we can show that the remaining terms make no contribution. We have for these terms that with $1\le r\le p-1$ we must have that $l$ is a multiple of $p$ (the innermost sum is zero otherwise and we may omit these values from $l$) and we get

$$[w^k] \frac{1}{p} \sum_{r=1}^{p-1} \exp\left(p \sum_{l\ge 1} (-1)^{pl-1} \frac{w^{pl}}{pl}\right) \\ = [w^k] \frac{1}{p} \sum_{r=1}^{p-1} \exp\left(- \sum_{l\ge 1} \frac{((-1)^p w^p)^{l}}{l}\right) \\ = [w^k] \frac{1}{p} \sum_{r=1}^{p-1} \exp\left(\log(1-(-1)^p w^p)\right) \\ = [w^k] \frac{1}{p} \sum_{r=1}^{p-1} (1-(-1)^p w^p) = \frac{p-1}{p} [w^k] (1-(-1)^p w^p) = 0.$$

This concludes the argument. (As a sanity check this even works for $k=1$ and $k=0$ where we get the values $1$ and $1/p+(p-1)/p=1,$ the latter representing the empty set whose element sum is zero and hence indeed divisible by $p.$)

A generic version of the above computation may be found at the following MSE link.

• Thank you, Marko Riedel for the link of similar problem. I'll try to study it. – carat Apr 3 '17 at 12:49