$d(n)$ is odd if and only if $n = k^2$ Can someone help me prove that $d(n)$ is odd if and only if $n = k^2$ for some integer $k$?
For reference:
$d(n)$ gives the number of positive divisors of $n$, including $n$ itself.

Consider $D$, the set of all divisors of $n$. 
Define a map $f: D \rightarrow D$ by $f(d) = \frac{n}{d}$, which is well defined (as $d$ is a divisor of $n$) and self inverse because $f(f(d)) = f(\frac{n}{d}) = \frac{n}{\frac{n}{d}} = d$. 
When $x < \sqrt{n}$ (as reals), then $f(x) > \sqrt{n}$ and vice versa, so $f(x) \neq x$ for all those $x$. So if $\sqrt{n}$ is not an integer, there is no fixed point for $f$ and $D$ is exactly divided in $D_1 = \{d \in D: d < \sqrt{n}\}$ and $D_2 = \{d \in D: d > \sqrt{n}\}$ and these have equal size, as $f$ is a bijection between them. So $|D|$ is even. 
So $n$ no square implies $d(n)$ is even. If $n$ is a square $D = D_1 \cup D_2 \cup \{\sqrt{n}\}$. Again, $f$ shows that $|D_1| = |D_2|$ and $d(n)$ is odd.
