TITLE: How can I compute the sum of $ {m\over\gcd(m,n)}$?
QUESTION [9 upvotes]: $$ \sum_{m =1}^n {m\over\gcd(m,n)}$$
For example,
for 1 it is 
$${1\over\gcd(1,1)} =1;$$
for 5 it is
$${1\over \gcd(1,5)}+{2\over \gcd(2,5)}+{3\over \gcd(3,5)}+{4\over \gcd(4,5)}+{5\over \gcd(5,5)}=\\
\frac11+\frac21+\frac31+\frac41+1 = \\
1+2+3+4+1= \\ 11$$

REPLY [4 votes]: If you define $S(n)$ as your sum:
$$S(n)=\sum_{m=1}^n \frac{m}{(m,n)}$$
then we will show that $2S(n)-1$ is multiplicative.  
You can rewrite the sum as:
$$S(n)=\sum_{d\mid n} \sum_{m=1}_{(m,n)=d}^n \frac{m}{d}$$
Setting $k=m/d$, we get:
$$S(n)=\sum_{d\mid n} \sum_{k=1}_{(k,n/d)=1}^{n/d} k = \sum_{d\mid n}\sum_{k=1}_{(k,d)=1}^d k$$
So let $$f(d) = \sum_{k=1}_{(k,d)=1}^d k$$
It is not hard to show that this $f(1)=1$ and $f(d)=\frac{1}{2}\phi(d)d$ when $d>1$.
So we get:
$$S(n)=\frac{1}{2}+\frac{1}{2}\sum_{d\mid n} \phi(d)d$$
Now $g(n)=\sum_{d|n} d\phi(d)$ is multiplicative, since $n\phi(n)$ is, so $g(n)$ is determined by $$g(p^a) = 1+\sum_{i=1}^a p^i\phi(p^i) = \\1+\sum_{i=1}^a p^{2i-1}(p-1) = \\1 + p(p-1)\sum_{i=1}^a p^{2i-2} = \\1+p(p-1)\frac{p^{2a}-1}{p^2-1}=\\ \frac{p^{2a+1}+1}{p+1}$$
And in general, if $n=\prod p_i^{a_i}$ then $$g(n)=\prod \frac{p_i^{2a_i+1}+1}{p_i+1}$$
And your original sum is:
$$S(n)=\frac{1+g(n)}2$$
So, for example, $$g(12)=g(2^2)g(3^1)= \frac{2^5+1}{2+1}\frac{3^3+1}{3} = 11\cdot 7 = 77$$
So when $n=12$, your sum is $S(12)=\frac{77+1}{2}=39$.
For $n=143$, $$g(143)=g(11)g(13)=\frac{11^3+1}{11+1}\frac{13^3+1}{13+1} = 111\cdot 157 = 17427$$ and your sum is $S(143)=\frac{17427+1}{2}=8714$.