For smaller values of $k$ it might be feasible to match the prime decomposition of $k$ to the product formula for $\phi(n)$, and then go through the different possible cases. For example with $k = 12$ (Ex. 1(c) of Chapter 2 of "Introduction to Analytic Number Theory" by Tom M. Apostol) :
$n = 13$ is an obvious solution as $\phi(p) = p - 1$ for any prime $p$, and clearly any solution $n$ is $\geq 13$.
Consider $n = p_1^{a_1} \cdots p_k^{a_k}$, where $p_i$ are distinct primes with $p_1 < p_2 < \ldots < p_k$, and $a_i \geq 1$.
From the product formula for $\phi(n)$ :
$$
\phi(n) = ( p_1^{a_1-1} \cdots p_k^{a_k-1} ) \cdot (\: (p_1-1) \cdots (p_k-1) \:) = m \cdot l \mbox{, say}
$$
where every factor $(p_i - 1)$ is even, except possibly the first which is $1$ when $p_1 = 2$.
If $2 \nmid l$ then $k = 1$ and $p_1 = 2 \therefore n = 2^{a_1}$, therefore from the product formula for the totient function, $\phi(n) = n/2$. In the present case this implies $n = 24$, but $\phi(24) = 8$, so below we can assume $2 \mid l$.
Since we require $m \cdot l = 12 = 2^2 \cdot 3$ and $2 \mid l$, from the prime decompositions we must have one of the following possibilities :
- $m = 2 \cdot 3$, $l = 2$
- $m = 3$, $l = 2^2$
- $m = 2$, $l = 2 \cdot 3$
- $m = 1$, $l = 2^2 \cdot 3$
Case (i) $n$ even.
Then $p_1 = 2$. If $k = 1$ then $n$ is a power of $2$ but this cannot give $\phi(n) = 12$ as seen above. Thus assume $k \geq 2$.
Then, in the product $l$, the factor $(p_1 - 1) = 1$ and the distinct factors $(p_2 - 1), \cdots, (p_k - 1)$ are all divisible by $2$.
Case (1) $\Rightarrow k = 2$ and $p_2 = 3$, to achieve $l = 2$. Thus the primes of $n$ are $2$, $3$. Since $m = 2 \cdot 3$ we must have $a_1 = a_2 = 2$. Thus $n = 2^2 \cdot 3^2 = \mathbf{36}$.
Case (2) $\Rightarrow k \leq 3$, otherwise there would be too many $2$'s in $l$. But $k = 2 \Rightarrow p_2 = 5 \Rightarrow$ primes of $n$ are $2, 5$, but $m = 3 \Rightarrow$ $3$ a prime of $n \therefore$ contradiction. And $k = 3 \Rightarrow p_2 - 1 = p_3 - 1 = 2 \Rightarrow p_2 = p_3 \Rightarrow$ contradiction. Thus case (2) is not possible.
Case (3) $\Rightarrow$ there is only one $2$ in $l$ $\Rightarrow$ $k = 2$. Then to achieve $l = 2 \cdot 3$, $p_2 = 7 \therefore$ primes of $n$ are $2, 7$, and $m = 2 \Rightarrow a_1 = 2, a_2 = 1$. Thus $n = 2^2 \cdot 7 = \mathbf{28}$.
Case (4) $\Rightarrow k \leq 3$. $k = 2 \Rightarrow p_2 - 1 = l = 12 \therefore$ primes of $n$ are $2, 13$ and $m = 1 \Rightarrow a_1 = a_2 = 1 \therefore$ $n = 2 \cdot 13 = \mathbf{26}$. $k = 3 \Rightarrow (p_2 - 1)(p_3 - 1) = 2^2 \cdot 3$ with $2 \mid (p_2 - 1)$ and $2 \mid (p_3 - 1) \Rightarrow p_2 - 1 = 2 \cdot 3$ and $p_3 - 1 = 2$ (or vice-versa) $\Rightarrow$ since $p_2 < p_3$, $p_2 = 3$ and $p_3 = 7$. Thus the primes of $n$ are $2, 3, 7$ and $m = 1 \Rightarrow a_1 = a_2 = a_3 = 1 \therefore n = 2 \cdot 3 \cdot 7 = \mathbf{42}$.
Case (ii) $n$ odd.
Here all $p_i$'s are odd, $k \geq 1$, and every factor $(p_i - 1)$ is even.
Case (1) $\Rightarrow k = 1$ and $p_1 = 3$. But $m = 2 \cdot 3 \Rightarrow p_1^{a_1-1} = 2 \cdot 3$ which is even - a contradiction as $p_1$ odd. Thus case (1) is not possible.
Case (2) $\Rightarrow k \leq 2$. $k = 1 \Rightarrow p_1 = 5$. But $m = 3 \Rightarrow p_1^{a_1-1} = 3 \Rightarrow$ contradiction as $p_1 = 5$. $k = 2 \Rightarrow p_1 - 1 = p_2 - 1 = 2 \Rightarrow p_1 = p_2 \Rightarrow$ contradiction. Thus case (2) is not possible.
Case (3) $\Rightarrow k = 1$ and then $p_1 = 7$. But $m = 2 \Rightarrow p_1^{a_1-1} = 2 \Rightarrow$ contradiction as $p_1 = 7$. Thus case (3) is not possible.
Case (4) $\Rightarrow k \leq 2$. $k = 1 \Rightarrow p_1 = 13$. Then $m = 1 \Rightarrow a_1 = 1 \therefore n = \mathbf{13}$. $k = 2 \Rightarrow$ since $2 \mid (p_1 - 1)$ and $2 \mid (p_2 - 1)$, so $(p_1 - 1) = 2 \cdot 3$ and $(p_2 - 1) = 2$ (or vice-versa). But $p_1 < p_2 \therefore$ $p_1 = 3, p_2 = 7$, and $3, 7$ are the prime factors of $n$. Since $m = 1$, $a_1 = a_2 = 1 \therefore n = 3 \cdot 7 = \mathbf{21}$.
Thus the solution is $\{13, 21, 26, 28, 36, 42\}$.