For what integers $n$ does $\varphi(n)=n-2$? I know that $\varphi(p)=p-1$, so it rules out the primes. I then tried to consider all powers of primes. It then turn out that only $2^2=4$ works
If 
$$
n = pq\\
\varphi(n)=(p-1)(q-1)=pq-p-q+q=n-p-q+1\\
\rightarrow 1-p-q=-2
$$
which would't work since we want n to be positive
I'm pretty stuck from here.
I also tried to reason that $\varphi(n)=n\prod (1-\frac{1}{p_i})$ but couldn't get anywhere.
Thanks in advance for any help.
 A: Assume $n$ has more than one prime factor. Let these prime factors be $p$, $q$. Since $p$ and $q$ and $n$ are not coprime with $n$, but $\phi(n)$ counts the number of numbers coprime to $n$, this implies $n-2=\phi(n)\le n-3$. Contradiction.
Thus, $n$ has one prime factor. So $n=p^{e}$ so some $p$ prime and $e$ natural. So $$p^{e}-2=n-2=\phi(n)=\phi(p^{e})=p^{e}-p^{e-1}$$
So $p^{e-1}=2$. By the Fundamental Theorem of Arithmetic, $p=2, e=2$,. So the only solution is $n=4$. We are done. 
A: *

*$n$ is even, say $n=2^a m$, where $m$ is odd and $a \geq 1$, we then have
$$2^am-2 = n-2 = \phi(n) = 2^{a-1} \phi(m) \leq 2^{a-1}m \implies 2m-2^{2-a} \leq m$$
This gives us that $m \leq 2^{2-a}$. Hence, only possibility is $a=2$, which gives us $m \leq 1$, which gives us $n=4$.

*$n$ is an odd prime: Then $\phi(n) = n-1 \neq n-2$

*$n$ is odd composite but has two distinct factors, i.e, $n=ab$, where $1<a < b < n$: Then clearly, we have $\gcd(n,a) = a \neq 1$, $\gcd(n,b) = b \neq 1$ and $\gcd(n,n) = n \neq 1$. Hence, if $a \neq b$, then $\phi(n) \leq n-3$.

*$n$ is odd composite but a prime square, i.e, $n=a^2$, where $1<a < n$ and $a$ is a prime: Since $a\geq 3$, we see that $\gcd(a,n) = \gcd(2a,n) = a$ (note that $2a < n$). Hence, again we have $\phi(n) \leq n-3$.


So only solution is $n=4$.
A: Since $n$ is not prime, it is divisible by some primes. Let $p$ be the smallest prime dividing $n$.  
Then $p$ and $n$ are not relatively prime with $n$. Since $\phi(n)=n-2$ these are the only two.
But then $2p$ is not relatively prime with $n$ either, and hence $n=2p$. 
Since $p$ is the smallest prime dividing $n$ and $n=2p$ is even, we get that $p=2$ and hence $n=4$.
A: Suppose $\psi (n)=n-2.$ Obviously $n>1.$ Let $P$ be the set of prime divisors of $n.$ For any $p\in P$ we have $$n(1-1/p)\geq n\prod_{q\in P}(1-1/q)=\psi (n)=n-2 \implies$$ $$\implies n(1-1/p)\geq n-2 \implies  p\geq n/2 \implies$$ $$\implies (p=n\lor p=n/2).$$ The last line above follows from $(p|n\land p\geq n/2).$
Now we cannot have $p=n,$ else $\psi (n)=\psi (p)=p-1=n-1.$ So we have $p\in P\implies p=n/2,$ so  the only prime divisor of $n$ is $n/2.$ But if $n/2$ is an integer then $2$ is a prime divisor of $n.$ So $2=p=n/2$ and $n=4.$
Therefore $\psi (n)=n-2\implies n=4.$ We also have (obviously) $n=4\implies \psi (n)=n-2.$
