Sum of all possible values of $\gcd(a-1,a^2+a+1)$ 
Find the sum of all possible values of
  $$\gcd(a-1,a^2+a+1)$$
  where $a$ is a positive integer.


\begin{align}
\gcd(a-1,a^2+a+1)&=\gcd(a-1,a^2+a+1-(a+2)(a-1))\\
&=\gcd(a-1,3)\\
&=\begin{cases} 3 & \textrm{if }a\equiv 1\quad(\textrm{mod }3) \\ 1 & \textrm{if }a\not\equiv 1\quad(\textrm{mod }3) \end{cases}
\end{align}
The sum is $4$.
