Let $n \ge 1$ be an integer. For each subset $S \subset \{1, 2, \ldots , 3n\}$, let $f(S)$ be the sum of the elements of $S$, with $f(\emptyset) = 0$. Determine, as a function of $n$, the sum $$\sum_{\mathclap{\substack{S \subset \{1,2,\ldots,3n\}\\ 3 \mid f(S)}}} f(S)$$where $S$ runs through all subsets of $\{1, 2,\ldots, 3n\}$ such that $f(S)$ is a multiple of $3$.
Problem
Source: 2018 Brazil 4th TST Day 1 #1
Tags: combinatorics, number theory, Sets
24.03.2019 00:00
Let $\omega=e^\frac{2\pi i}{3}, A(n)=\sum_{\mathclap{\substack{S \subset \{1,2,\ldots,3n\}\\ 3 \mid f(S)}}} f(S)$ and $$g(X)=(1+X)(1+X^2)\cdots(1+X^{3n})=\sum_{S \subset \{1,2,\ldots,3n\}} X^{f(S)}$$$$\Rightarrow Xg'(X)=\sum_{S \subset \{1,2,\ldots,3n\}} f(S)X^{f(S)}.$$Observe that \begin{align*} g'(X)&=g(X)\left(\sum_{i=1}^{3n} \frac{iX^{i-1}}{1+X^i}\right) \\ g'(1)&=g(1)\left(\sum_{i=1}^{3n} \frac{i}{1+1}\right)=2^{3n-2}\cdot 3n(3n+1) \\ \omega g'(\omega)&=\omega g(\omega)\left(\sum_{i=1}^{3n} \frac{i\omega^{i-1}}{1+\omega^i}\right)=2^n\left(\frac{3n(n+1)}{4}-\frac{n(3n+1)}{2}\omega-\frac{n(3n-1)}{2}\omega^2\right) \\ \omega^2 g'(\omega^2)&=\omega^2 g(\omega^2)\left(\sum_{i=1}^{3n} \frac{i\omega^{2(i-1)}}{1+\omega^{2i}}\right)=2^n\left(\frac{3n(n+1)}{4}-\frac{n(3n-1)}{2}\omega-\frac{n(3n+1)}{2}\omega^2\right) \end{align*}and therefore \begin{align*} 3A(n)&=g'(1)+\omega g'(\omega)+\omega^2 g'(\omega^2) \\ &=3n(3n+1)(2^{3n-2}+2^{n-1}) \\ \Rightarrow A(n)&=n(3n+1)(2^{3n-2}+2^{n-1}). \end{align*}I hope I didn't mess up.
17.05.2021 16:59
Much easier solution. Let $U$ denote the required sum. Note that $1+2+\cdots+3n$ is divisible by $3$. As $f(S)+f(S^c) = \dfrac{3n(3n+1)}2$ we have $3\mid f(S)$ if and only if $3\mid f(S^c)$ $$\implies U = \sum_{\mathclap{\substack{S \subset \{1,2,\ldots,3n\}\\3 \mid f(S)}}} f(S) \hspace{0.25cm} =\hspace{0.25cm}\sum_{\mathclap{\substack{S \subset \{1,2,\ldots,3n\}\\3 \mid f(S)}}} f(S^c)$$$$\implies 2 U = \sum_{\mathclap{\substack{S \subset \{1,2,\ldots,3n\}\\3 \mid f(S)}}} f(S)+f(S^c)= \frac{3n(3n+1)}2 \hspace{0.25cm}\sum_{\mathclap{\substack{S \subset \{1,2,\ldots,3n\}\\3 \mid f(S)}}} 1 $$$$\implies U = \frac{3n(3n+1)}4 a_n$$Where $a_n$ denotes the number of subsets $S$ of $\{1,2,\cdots,3n\}$ which satisfy $3\mid f(S)$. Now we find $u_n$ recursively. Consider any subset $S'$ of $\{1,2,\cdots,3n-3\}$, then we adjoin one set from one of the following pairs to it - $\{3n\}$ or $\{3n-1,3n-2\}$ if $3\mid f(S')$ $\{3n-1\}$ or $\{3n,3n-1\}$ if $3\mid f(S')+1$ $\{3n-2\}$ or $\{3n,3n-2\}$ if $3\mid f(S')+2$ And we get $2\times 2^{3n-3}=2^{3n-2}$ sets $S \subset \{1,2,\cdots,3n\}$ with $3 \mid f(S)$ . Any set not generated by this method must contain all of $\{3n,3n-1,3n-2\}$ or none of it and in either case it is counted in $a_{n-1}$. Hence $a_n = 2a_{n-1}+2^{3n-2}$, now to solve this substitute $b_n= \frac{a_n}{2^n}$, as $a_1=4, b_1=2$. $b_n = b_{n-1}+4^{n-1} \implies b_n = 2+4+4^2+\cdots+4^{n-1}=\frac{4^n+2}{3}$. And hence $a_n = \frac{2^{n+1}(2^{2n-1}+1)}{3}$ $$\implies U = 2^{n-1}(2^{2n-1}+1)n(3n+1)$$