Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to find this

$$ \sum_{k=1}^n \gcd(k,n)$$

but I don't know how to solve. Does anybody can help me to finding this problem.


share|cite|improve this question
Do you know how many integers $k$ in the range $1 \leq k \leq n$ are relatively prime to $n$ so that $\gcd(k,n) = 1$? (Hint: Read about Euler's totient function.) – Dilip Sarwate Apr 22 '12 at 16:03
n $\leq$ 200000. Ok I will read Euler's totient function. – Elmi Ahmadov Apr 22 '12 at 16:32
up vote 9 down vote accepted

This is Pillai's arithmetical function as in OEIS A018804

Formulae given there include $$\sum_{d|n} d \,\phi(n/d)$$ and $$\sum_{d|n} d \, \tau(d) \, \mu(n/d)$$ where $\phi(n)$ is Euler's totient function, $\tau(n)$ is the number of divisors and $\mu(n)$ is the Möbius function.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.