For $a\in\mathbb{N}^*$ we define:
$$ S(a)=\sum_{0\leq k \leq a-1} e^{i\pi \frac{k^2}{a}} $$ or equivalently, if $\omega=e^{\frac{i\pi}{a}}$ is the primitive $2a$-th roots of units, we could write: $$S(a)=1+\omega+\omega^{4}+\omega^{9}+\dots+\omega^{(a-1)^2}$$
How could you prove that $S(a)=1$ for odd values of $a$ and $S(a)=(i+1)\sqrt{(a/2)}$ if $a$ is even?