For which $n$ is $ \int \limits_0^{2\pi} \prod \limits_{k=1}^n \cos(k x)\,dx $ non-zero? I can verify easily that for $n=1$ and $2$ it's $0$, $3$ and $4$ nonzero, $4$ and $5$ $0$, etc. but it seems like there must be something deeper here (or at least a trick).
 A: Apparently, this isn't an easy question. See here for $n \leq 10$.
EDIT: As Jason pointed out below, the last paragraph on the linked page sketches the proof that the integral is non-zero iff $n$ $=$ $0$ or $3$ mod $4$ (that is, iff $n \in \lbrace 3,4,7,8,11,12,\ldots\rbrace$).
A: Write $\cos(kx)=(e^{ikx}+e^{-ikx})/2$. Obtain
$$\begin{array}{ll} \int_0^{2\pi}\prod_{k=1}^n\cos(kx)dx & =\int_0^{2\pi} \prod_{k=1}^n \frac{e^{k i x} + e^{- k i x}}{2} dx \\
 & = 2^{-n}\int_0^{2\pi} e^{-(1+2+\cdots+n) \cdot i x} \prod_{k=1}^n \left( 1 + e^{2 k i x} \right) dx  \\
 & =2^{-n}\int_0^{2\pi}e^{-n(n+1)/2\cdot ix}\sum_{\sigma\in\Sigma} e^{2\sigma ix}dx \\
 & =2^{-n}\sum_{\sigma\in\Sigma}\int_0^{2\pi}e^{(2\sigma -n(n+1)/2)\cdot ix}dx\end{array}$$
where $\Sigma$ is the multiset of numbers comprised of the sums of subsets of $\{1,\cdots,n\}$. The integral in the summand is given by $+1$ if $2\sigma=n(n+1)/2$ and $0$ otherwise. Therefore the sum is nonzero if and only if there is a $n(n+1)/4\in\Sigma$, i.e. $n(n+1)/4$ can be written as a sum of numbers taken from the set $\{1,\cdots,n\}$. Firstly $4\mid n(n+1)\Leftrightarrow n\equiv 0,-1$ mod $4$ is necesesary, and moreover
Lemma. Any number $0\le S\le n(n+1)/2$ may be written as a sum of numbers in $\{1,\cdots,n\}$.
Proof. $S=0$ corresponds to the empty product. $S=1$ corresponds to the term $1$ itself. Otherwise suppose the claim holds true for $n$ as induction hypothesis, and we seek to prove the claim still holds true for $n+1$. Let $0\le S\le (n+1)(n+2)/2$. If $S\le n(n+1)/2$ then simply take the numbers from $\{1,\cdots,n\}$ via induction hypothesis, otherwise $0\le S-(n+1)\le n(n+1)/2$ and we may invoke the induction hypothesis on $S-(n+1)$, then add $n+1$ to that sum to obtain a sum of elements from $\{1,\cdots,n,n+1\}$ which add up to $S$.
Therefore, $n\equiv 0,-1$ mod $4$ is both necessary and sufficient for the integral to be positive.
A: Hint: Start as anon did with
$$
\int_0^{2\pi}\prod_{k=1}^n\cos(kx)\,\mathrm{d}x
=\int_0^{2\pi}e^{-i\frac{n(n+1)}{2}x}\prod_{k=1}^n(1+e^{i2kx})\,\mathrm{d}x\tag{1}
$$
which would be $2\pi$ times the coefficient of $x^{n(n+1)/2}$ in
$$
\prod_{k=1}^n(1+x^{2k})\tag{2}
$$
$(2)$ is the number of ways to write $n(n+1)/2$ as the sum of distinct even integers $\le2n$.
So $(1)$ is non-zero precisely when you can write $n(n+1)/2$ as the sum of distinct even integers $\le2n$ (a much simpler problem).

Claim: $\dfrac{n(n+1)}{2}$ can be written as the sum of distinct even integers no greater than $2n$ in at least one way precisely when $n\in\{0,3\}\pmod{4}$.
Proof: By induction.
If $n\in\{1,2\}\pmod{4}$, then $\dfrac{n(n+1)}{2}$ is odd, and so cannot be written as the sum of even integers.
Suppose that $n\in\{0,3\}\pmod{4}$ and $\dfrac{n(n+1)}{2}$ can be written as the sum of distinct even integers no greater than $2n$. Then
$$
\frac{(n+4)(n+5)}{2}=\frac{n(n+1)}{2}+(2n+4)+(2n+6)
$$
Thus, if the statement is true for $n$, it is true for $n+4$.
Once we note that $\dfrac{3(3+1)}{2}=2+4$ and $\dfrac{4(4+1)}{2}=4+6$, we are done. QED
