Closed form of $\int\limits_0^{2\pi} \prod\limits_{j=1}^n \cos(jx)dx$ and combinatorial link I have been trying to find a closed form for this integral:
$$I_n = \int\limits_0^{2\pi} \prod_{j=1}^n \cos(jx)dx$$
The first values are: $I_1=I_2=0,I_3=\frac{\pi}{2}, I_4=\frac{\pi}{4}, I_5=I_6=0, I_7=\frac{\pi}{8}, I_8=\frac{7\pi}{64}$
I am not able to see here a clean pattern except that for $n=4k+1,4k+2$ the integral should be zero. If someone could give me a hint I would appreciate it.
EDIT
As suggested by Winther in the comments, the problem can be viewed from a combinatorial standpoint. Looking at the complex exponential representation one gets $2^n$ integrals of the form $\int_0^{2\pi}e^{iNx}dx$, which is only nonzero, if $N=0$. The integral evaluates to $\frac{M\pi}{2^{n-1}}$, where $M$ is the number of nonzero integrals.
So one needs to find $M$, which is the number of binary numbers $b$ for which holds that
$$\sum_{k=1}^n (2b_k-1)k = 0$$
where $b_k$ is the k-th digit of $b$.
With this, it is easy to see if for some $b$ it holds, it will also hold for $\overline{b}$ (each digit is inverted).

As pointed out in the comments, the result is
$$ I_n = a_n \frac{2\pi}{2^{n}} $$
where $a_n$ is the numbers of solutions of $\sum_{j=1}^n s_n \,j =0$ where $s_j \in \{1,-1\}$ (or number of ways of marking a subset of $\{ 1,2, \cdots n\}$ such that the sum of the marked subset equals the sum of the unmarked subset). This is given by OEIS A063865.
Asymptotics (for $n=0,3 \pmod 4$): $$I_n \approx \sqrt{24 \pi} \, n^{-3/2} $$
Ref
