Is the following true for all interger $n>1$?
GCD of $n$ and $\sum_{i=1}^{n} \chi_{n,1}(i) i^{-2} \bmod n$ is $\begin{cases}n&\text{if }3\nmid n,n\ne2^a\\ n&\text{if }3\mid n\text{ and }n\text{ has a prime factor of the form }3k+1\\ \frac n3&\text{if }3\mid n\text{ and }n\text{ has no prime factor of the form }3k+1\\ \frac n2&\text{if }n=2^a\end{cases}$
where $\chi _{m,1}(a)$ denotes the principal character mod $m$.
Example
For $n=5$, WA computes $\sum_{i=1}^{5} \chi_{5,1}(i) i^{-2} \bmod 5=10$, so $\gcd(5,10)=5=n$.
For $n=8$, WA computes $\sum_{i=1}^8 \chi_{8,1}(i) i^{-2} \bmod 8=4$, so $\gcd(8,4)=4=\frac{n}2$.
For $n=15$, WA computes $\sum_{i=1}^{15} \chi_{15,1}(i) i^{-2} \bmod 15=20$, so $\gcd(15,20)=5=\frac{n}3$.
For $n=21$, WA computes $\sum_{i=1}^{21} \chi_{21,1}(i) i^{-2} \bmod 21=84$, so $\gcd(21,84)=21=n$.
A050931 is numbers that has a prime factor of the form $3k+1$.
Formula
Since $\{i\bmod n:\gcd(i,n)=1\}=\{i^{-1}\bmod n:\gcd(i,n)=1\}$, we can replace $i^{-2}$ with $i^2$:$$\sum_{i=1}^{n} \chi_{n,1}(i) i^{-2} \bmod n=\sum_{i=1}^{n} \chi_{n,1}(i) i^2 \bmod n$$ By Möbius inversion formula $$\sum_{1\le i\le n\atop\gcd(i,n)=1}i^2 =\sum_{d|n}\mu(d)\sum_{1\le k\le \frac{n}{d}}d^2 k^2\\ =\frac{n}{6}\sum_{d|n}d\mu(d) \left(\frac{n}{d}+1\right)\left(\frac{2n}{d}+1\right)\\ =\frac{n}{6}\sum_{d|n}\frac{d^2+3dn+2n^2}{d}\mu(d)\\ =\frac{n}{6}\sum_{d|n}d\mu(d)+\frac{n^2}{3}\sum_{d|n}\frac{n}{d}\mu(d)\\ =\frac{n}{6}\prod_{\text{prime }p|n}(1-p)+\frac{n^2}{3}\varphi(n)$$