Proof

The set V = {1, ... ,n} is the disjoint union of the sets

Vd = {m V | gcd(m,n) = d},

where d runs through the set of positive divisors of n (in which case also n/d runs through the set of positive divisors of n.)

For multiples m, n of d, we have gcd(m,n) = d if and only if gcd(m/d,n/d) = 1. The set Vd therefore also equals

{dm' V | gcd(m',n/d) = 1}.

Hence Vd contains (n/d) elements and

n = d | n, d > 0(d).

Taking apart the summand (n) (occurring for d = n), and bringing the remaining summation to the other side, we find the required formula.