I am having problems proving the following: For what values of $q$ does the following relationship hold $$\sum_{\substack{1\leq d < q\\ \gcd(d,q)=1}}\!\!\!\cos\left(2\pi \cdot \frac{d}{q}\right) =0$$
I have found by computer analysis this may hold true for $q=p^r \cdot k$ where $p$ is any prime and $k$ is an integer and $r$ is an integer greater than one. For example $$q=4,8,9,12,16,18,20,24,25,27,28,32,36,40,44,45,48,49,50,52,54,56,60,63,64,68,72,75,76,80,81,84,88,90,92,96,98,99,100,104,108,112,116,117,120,121,124,125,126,128,132,135,136,140,144,147,148,150,152,153,156,160,162,164,168,169,171,172,175,176,180,184,188,189,192,196,198,200,204,207,208,212...$$ For instance for $q=12$ we have $$\cos\left(2\pi\cdot \frac{1}{12}\right)+\cos\left(2\pi\cdot \frac{5}{12}\right)+\cos\left(2\pi\cdot \frac{7}{12}\right)+\cos\left(2\pi\cdot \frac{11}{12}\right)=0$$
But I am unable to prove this for the general case $q=p^r\cdot k$. Any help would be greatly appreciated.