TITLE: Is it always true that $\sum_{i=1}^{a-1}(-1)^i(a,i)\ge-1$?
QUESTION [8 upvotes]: Following is an experimental math claim.
We denote $(a,b)=\gcd(a,b)$.
Let $$G(a)=\sum_{i=1}^{a-1}(-1)^i(a,i).$$
Note:
$$  G(a) =
\begin{cases}
0,  & \text{if $a\equiv 1\pmod4$} \\
\text{odd},  & \text{if $a\equiv 2\pmod4$} \\
0,  & \text{if $a\equiv 3\pmod4$} \\
\text{even},  & \text{if $a\equiv 0\pmod4$.} 
\end{cases}$$

Can it be shown that for every $a\in\mathbb{Z}_{\ge2}$, $G(a)\ge-1$?

Table
$$\begin{array}{|c |c |}  \hline a & G(a) \\ \hline
2 & -1  \\  \hline
3 & 0  \\ \hline
4 &0 \\ \hline
5 &0 \\ \hline
6 &-1 \\ \hline
7 &0 \\ \hline
8 &4 \\ \hline
9 &0 \\ \hline
\vdots &\vdots  \\ \hline
 \end{array}$$
source code PARI/GP
for(a=1,10000,if(sum(i=1,a-1, (-1)^i*gcd(a, i))<-1,print([a])))

REPLY [5 votes]: $$G(a)+(-1)^aa=\sum_{i=1}^{a} (-1)^i (a,i)=\sum_{d|a} d \sum_{\substack{ l \\ (l, a/d)=1}} (-1)^{dl}=T(a).$$
When, $a$ is odd, $d, a/d$ is also odd. Hence, $$\sum_{\substack{l, \\ (l,a/d)=1 \\ d<a}} (-1)^l =0.$$ So, $T(a)=(-1)^aa \rightarrow G(a)=0$.
Now, for $a=2^{r_0}m, m=\prod_{i=1}^s p_i^{r_i}$ odd,
$$
T(a)=\sum_{\text{$d$ even}} d\phi(a/d) - \sum_{\text{$d$ odd}} d\phi(a/d)
$$
(because, for $d$ even $(-1)^d=1$, and for $d$ odd, $a/d$ even, so $l, dl$  is odd).
\begin{align*}
& {}=a\sum_{l\mid\frac{a}{2}} \frac{\phi(l)}{l}-\sum_{l \mid m}\frac{\phi(2^rl)}{2^rl} \\
& {}=a(\sum_{l\mid\frac{a}{2}} \frac{\phi(l)}{l}-\frac{1}{2}\sum_{l|m}\frac{\phi(l)}{l}).
\end{align*}
Now, $\sum_{d\mid n} \frac{\phi(d)}{d}=\prod_{i} (1+(1-\frac{1}{p_i})r_i)$, where $n=\prod_i p_i^{r_i}$.
Using this to the sum we get, the explicit formula for $G(a)$:
$$
G(a)=\frac{ar_0}{2p_1p_2\dotsm p_s}\prod_{i=1}^{s} (p_i(r_i+1)-r_i) -a.
$$
It's easy to see from the formula that $G(a)$ is odd when $r_0=1$ and even when $r_0>1$, because all $p_i$ are odd, hence each $p_i(r_i+1)-r_i$ is odd, and $a$ is even.
More compactly, $G(a)=a[\frac{r_0}{2}\prod_{i=1}^{s} (r_i+1-\frac{r_i}{p_i})-1]$.
Surely, $G(a) \geq -1$. It's $-1$, for $a=2p$ types, e.g. $a=6$.