# A sum of Ramanujan sums

I have the following question about Ramanujan sums.

(All vectors and matrices here will be understood to have integer entries.)

Let $X_q=\{ (x_1,...,x_R)|1\leq x_i\leq q\}$ and let, for any $R\times R$ matrix $B$ with rows $\mathbf b_i$,

where $c_q(n)$ is Ramanujan’s sum. Suppose an $R\times R$ matrix $A$ with determinant $D$ is given and denote by $I$ the identity matrix. Then my question would be:

Does

depend only on $(q,D)$?

In fact I thought the sum would be zero except for the case (q,D)=1 but I’m not so sure this is true.

Why might it be true? Write $d_i$ for the $i$-th elementary divisor of $A$. Then on considering the Smith normal form of $A$ and after using $c_{dq}(dn)=f(q,d)c_q(n)$ we have, up to a function depending only on $q$ and $(q,d_i)$,

where $Q=Q(A)$ is invertible and $E=(e_{i,j})$ is a diagonal matrix with

It seems to me plausible that this last sum is zero except for when $(q,d_R)=1$, which would be perfect. Testing thousands of $3\times 3$ matrices gives me always zero, so I do start to believe it. Could it be true? And along which lines should I be thinking if I want to prove it?

Any suggestions would be very much appreciated!