If $A\subseteq\mathbb{N}$ is a subset of the positive integers, we let $$\mu^+(A) = \lim\sup\_{n\to\infty}\frac{|A\cap\{1,\ldots,n\}|}{n}$$ be the *upper density* of $A$.


For $n\in\mathbb{N}$ we let $\sigma(n)$ be the number of divisors of $n$, the numbers $1$ and $n$ included.


Do we have $\mu^+\big(\sigma^{-1}(\{k\})\big) = 0$ for all $k\in\mathbb{N}$? If not, what is the value of $\sup\big\{\mu^+\big(\sigma^{-1}(\{k\})\big):k\in\mathbb{N}\big\}$?



Distribution of pre-images of the divisor function $\sigma$
Notice that $\sigma(p^{k-1}) = k$ and so the image of $\sigma$ is all of $\mathbb{N}$.


By the way, $\sigma$ is usually used for the sum of divisors function, and it is more standard to use $d$ or $\tau$ for your function.


EDIT: I misread the question. I will use $\tau$ instead of $\sigma$.


I claim that $\mu ^ {+}(\tau^{-1}(\{k\})) = 0$. Take a number $m$ in this set, and let us look at $m$'s prime factorization: $m = p\_1^{\alpha\_1} p\_2^{\alpha\_2}\cdots p\_r^{\alpha\_r}$. Notice that there are finitely many options for the $\alpha\_i$ (up to a permutation), because $(\alpha\_1 + 1)(\alpha\_2 + 1) \cdots (\alpha\_r + 1)=k$, so it is enough to show that the upper density of numbers of the form $p\_1 ^ {\alpha\_1} p\_2 ^{\alpha\_2} \cdots p\_r^{\alpha\_r}$ where $r, \alpha\_i$ are fixed is zero.


Let us look at numbers in this set that are at most $x$. Then if we fix $p\_1$, we need to choose primes $p\_2, \cdots p\_r$ such that $p\_2 ^{\alpha\_2} \cdots p\_r^{\alpha\_r} \leq \frac{x}{p\_1 ^{\alpha\_1}}$.


By induction we can assume that the amount of numbers of the form $p\_2 ^{\alpha\_2} \cdots p\_r^{\alpha\_r}$ which are at most $x$ is $o(x)$, and if $\alpha\_1 \geq 2$ then this shows that the amount of numbers of the form $p\_1 ^{\alpha\_1} p\_2 ^{\alpha\_2} \cdots p\_r^{\alpha\_r}$ is $o(x)$ by summing over the options of $p\_1$ (and using the fact that $\sum\_{p} \frac{1}{p^2} \leq \sum\_{n} \frac{1}{n^2}$ converges. Therefore it is enough to solve in this case where all $\alpha\_i$ are 1, that is to show that the amount of numbers of the form $p\_1 \cdots p\_r$ up to $x$ is $o(x)$ (for $r$ fixed).


Fixing $p\_1$ we see that $p\_2$ can be any prime that is at most $\frac{x}{p\_1}$. and then $p\_3$ can be anything that is at most $\frac{x}{p\_1 p\_2}$, ... and $p\_r$ is at most $\frac{x}{p\_1 p\_2 \cdots p\_{r-1}}$. So we see that the amount of numbers at most $x$ is


$$\sum\_{p\_1 \leq x} \sum\_{p\_2 \leq \frac{x}{p\_1}} \cdots \sum\_{p\_{r-1} \leq \frac{x}{p\_1 \cdots p\_{r-2}}} \pi (\frac{x}{p\_1 \cdots p\_{r-1}})$$


From here we can use the simple bound $\pi (x) \leq \frac{cx}{log x}$ for some constant $c$ and see that this sum is small.


