stylistic:tone, structural:reformatting
Properties

∑ k = 1 n gcd (k, n) = ∑ d | n d ϕ (n d) = n ∑ d | n φ (d) d = n ∏ p | n (1 + ν p (n) (1 − 1 p)) {\displaystyle \sum _{k=1}^{n}\gcd(k,n)=\sum _{d|n}d\phi \left({\frac {n}{d}}\right)=n\sum _{d|n}{\frac {\varphi (d)}{d}}=n\prod _{p|n}\left(1+\nu _{p}(n)\left(1-{\frac {1}{p}}\right)\right)} where ν p (n) {\displaystyle \nu _{p}(n)} is the p -adic valuation. (sequence A018804 in the OEIS)