In my number theory textbook, there is a theorem about Euler's Phi Function it says:
A Theorem:
If $R$ is a reduced residue system modulo $n$: $R=\{a\in C \mid \gcd(a,n)=1\}$ Where $C$ is a complete residue system modulo $n$, so:
$$\sum_{a\in R}a=\phi(n)\cdot \frac{n}{2}$$ Where $\sum_{a\in R}a$ is the sum of all elements in $R$.
The Proof:
since R is a reduced residue system mod $n$ so $\mid R\mid = \phi(n)$ Hence we can suppose that $R=\{a_1,a_2,...,a_{\phi(n)}\}$ Thus: $$S=\sum_{a\in R}a=\sum_{i=1}^{\phi(n)}a_i$$ But since $\gcd(a_i,n)=1 \iff \gcd(n-a_i,n)=1$ so :$$\sum_{i=1}^{\phi(n)}a_i=\sum_{i=1}^{\phi(n)}(n-a_i)$$ $$ \implies2S = \sum_{i=1}^{\phi(n)}a_i+\sum_{i=1}^{\phi(n)}(n-a_i)=\phi(n)\cdot n$$ $$\iff S= \phi(n)\cdot \frac{n}{2}$$
Ok Everything is clear but this transition: $$\gcd(a_i,n)=1 \iff \gcd(n-a_i,n)=1$$ is not clear for me, and even if it is how can this statement implies this ?$$\sum_{i=1}^{\phi(n)}a_i=\sum_{i=1}^{\phi(n)}(n-a_i)$$