The number of positive integers less than 1000 with an odd number of divisors

The answer is number of perfect squares less than equal to the given number, as we know perfect squares have odd number of divisors. Number of divisors of any number can be calculated by decomposing it into prime factors. If $n=p_1^{e_1}p_2^{e_2}\ldots p_n^{e_n}$ then number of divisors is $(e_1+1)(e_2+1)\ldots(e_n+1)$. Let $n = a^2$, then if $d$ is a factor then so is $\frac{n}{d}$. Thus we see that the factors are in pairs except for a because $\frac{n}{a} = a$. Thus total number of factors is $2x+1$ where $x$ is number of factors less than $a$. So odd number of factors.


They are the squares so the answer is $\lfloor \sqrt{1000} \rfloor = 31$. To see this notice that the number of divisors of a number is the product of each exponent plus one, i.e. $n = \prod{p_i^{e_i}}$ and $\tau(n) = \prod{(e_i+1)}$. If $\tau(n)$ is odd then all $e_i$ are even which means $n$ is a square.


If we allow division by 1 and by the number it self then all the prime numbers have exactly two divisors so we can discount all the prime numbers.

Now consider the composite numbers that are not a perfect square say 6. This is 1x6 or 2x3 so we can discount all these too.

Finally we consider the composite numbers that are perfect squares say 4. This is 1x4 or 2x2. It is therefore divisible by an odd number of factors. This is true for all perfect squares and since the square root of 1000 is just over 31.6 there will be 31 natural numbers less than 1000 that have an odd number of factors

$1^2 = 1$, $2^2 = 4$, $3^2 = 9$, ... $31^2 = 961$