Let $n = \prod p_i^{k_i}$ be the prime factorization of $n$.

Then $\phi(n) = \prod p_i^{k_i - 1}(p_i-1)$.

So if $2 = 1^w*2^1 = \prod p_i^{k_i - 1}(p_i-1)$ then all the $(p_i -1) $ equal either $1$ or $2$ so all the $p_i$ equal either $2$ or $3$.

So either we have

$n = p^k$ and either $p=2$ or $3$;

So 1) $n = 2^k$ or 2)$n = 3^k$

Or we have

3) $n = 2^k3^m$

If 1) then $\phi(n) = 2^{k-1}(2-1) = 2$ so $k= 2$ and $n=4$.

If 2) then $\phi(n) = 3^{k-1}(3-1) = 2$ so $k = 1$ and $n =3$.

If 3) then $\phi(n) = 2^{k-1}(2-1)3^{m-1}(3-1)$ so $k =1$ and $m =1$ and $n=6$.

Those are the only three cases.


It's fairly trivial to prove that $\phi(n)$ is divisible by $2$ for any $n \ge 3$. So if $n$ has two coprime factors, both bigger than $3$ we have that $4 \mid \phi(n)$. Therefore the only remaining cases are $n=2p^k$ and $n=p^k$, where $p$ is an odd prime. You should be able to derive a constrain for $p$ and $k$ from here, by noting that $\phi(p^k) \ge \phi(p) = p-1$


For every prime $p\geq 4$ and ever natural number $k$ you have $p^k-p^{k-1}>2$. Since $φ(ab)=φ(a)φ(b)$ if $(a,b)=1$ this means that if you have a prime number $p\geq4$ which $p|n$ then $φ(n)>2$. Therefore only $2$ and $3$ can divide $n$. But $2^{k_1}-2^{k_1-1}=2^{k_1-1}$ and $3^{k_2}-3^{k_2-1}\geq2$ for $k_2\geq2$ therefore $k_2$ can be only $0,1$ and $k_1$ can be only $0$,$1$,$2$.

Now we check.

If $k_1=0$ then only $3|n$ so $n=3$.

If $k_1=1$ then $2$ doesn't contribute to the function so again $k_2=1$ and now $n=6$.

Finally, if $k_1=2$ then $φ(4)=2$ and this forces $k_2=0$.

So you were right, $n$ can only be $3,4,6$.