Divisor Sum is Odd iff Argument is Square or Twice Square

Theorem
Let $\sigma: \Z \to \Z$ be the sigma function.

Then $\sigma \left({n}\right)$ is odd $n$ is either square or twice a square.

Proof
Let $n$ be an integer such that $n \ge 2$.

Let the prime decomposition of $n$ be:
 * $n = p_1^{k_1} p_2^{k_2} \ldots p_r^{k_r}$

Then from Sigma of Integer we have that:
 * $\displaystyle \sigma \left({n}\right) = \prod_{1 \mathop \le i \mathop \le r} \frac {p_i^{k_i + 1} - 1} {p_i - 1}$

That is:
 * $\displaystyle \sigma \left({n}\right) = \prod_{1 \mathop \le i \mathop \le r} \left({1 + p_i + p_i^2 + \ldots + p_i^{k_i}}\right)$

Let $\sigma \left({n}\right)$ be odd.

Then all factors of $\displaystyle \prod_{i \mathop = 1}^r \left({1 + p_i + p_i^2 + \ldots + p_i^{k_i}}\right)$ are odd (and of course $\ge 3$).

For $1 + p_i + p_i^2 + \ldots + p_i^{k_i}$ to be odd, one of two conditions must hold:
 * $p_i$ is even (so that all terms of $1 + p_i + p_i^2 + \ldots + p_i^{k_i}$ are even except the $1$);
 * $k_i$ is even (so that $1 + p_i + p_i^2 + \ldots + p_i^{k_i}$ has an odd number of odd terms).

In the first case, that means $p_i^{k_i}$ is a power of $2$.

In the second case, that means $p_i^{k_i}$ is a square.

The result follows.

The argument reverses.