TITLE: How to find this LCM sum function? $ \text{lcm}(1,n) +\text{lcm}(2,n) +\cdots+\text{lcm}(n,n)$
QUESTION [5 upvotes]: Given an integer $n$, How do we find $$S=\text{lcm}(1,n) + \text{lcm}(2,n) +\ldots+ \text{lcm}(n,n)$$
I know how find the $\gcd$ sum $$\gcd(1,n) + \gcd(2,n)  +\cdots+\gcd(n,n)$$
Because there is $$\sum{\phi(\frac{n}{i}) * i}$$ where $i|n$. But how do I use it to calculate $\text {lcm}$ ? 
I found a formula googling here . But there is no proof there, and the research paper journal is unreadable for me (i.e I can't understand the hard mathy notations). So it would be helpful if someone could explain how this formula came.

REPLY [12 votes]: Lemma 1: $\operatorname{lcm}(a, n) + \operatorname{lcm} (n-a, n) = \frac{ an } { \gcd(a, n)} + \frac{ (n-a)n} { \gcd(n-a, n)} = \frac{ n\times n} { \gcd(a,n) }$.
Lemma 2:  $\sum \frac{n}{\gcd(a,n)} = \sum_{f \mid n} \frac{n}{f} \times \phi(\frac{n}{f} ) = \sum_{d\mid n} d\phi(d)$, 
Proof: consider what happens if $ \gcd(a,n) = f \mid n$. It appears $\phi(\frac{n}{f})$ times on the LHS, and each time it has value of $ \frac{n}{f}$. Now substitute $ d = \frac{n}{f}$, which is also a divisor of $n$.
Now, to your problem, pull out $\operatorname{lcm}(n,n) = n$.
We have $ 2 \sum_{a=1}^{n-1} \operatorname{lcm}(a,n) = \sum \left[\operatorname{lcm}(a,n) + \operatorname{lcm} (n-a, n) \right] = n \sum \frac{n}{\gcd(a,n)} = n \times \sum_{d\mid n} d\phi(d).$
Add back $\operatorname{lcm}(n,n)=n$, and you get the formula in OEIS.