TITLE: Find all positive integers $n$ such that $\varphi(n)$ divides $n^2 + 3$
QUESTION [5 upvotes]: This was the Question:- Find all positive integers $n$ such that $\varphi(n)$ divides $n^2 + 3$
What I tried:-
I knew the solution and explanation of all positive integers $n$ such that $\varphi(n)\mid n$ .
That answer was when $n = 1$, or $n$ is of the form of $2^a$ or $2^a3^b$ . 
I tried to relate this fact with this problem in many ways, but couldn't get to a possible solution.
Any hints or suggestions will be greatly appreciated

REPLY [3 votes]: Note that $\phi(n)=1$ if and only if $n=1,2$, and even if and only if $n>2$. Therefore, $\boxed{n=1,2}$ are both solutions to
$$ \phi(n) \mid (n^2+3). \quad \ldots \quad (1) $$
Henceforth, assume $n>2$. Then $\phi(n)$ is even, and so $n$ must be odd. But then $n^2+3 \equiv 4\pmod{8}$, so $n^2+3=4m$, with $m$ odd.
Since $\phi$ is multiplicative:
$$ \phi(mn) = \phi(m) \cdot \phi(n) $$
whenever $\gcd(m,n)=1$, and
$$ \phi(p^{\alpha}) = p^{\alpha-1}(p-1), $$
we have
$$ \phi(n) = \prod_{p^{\alpha}\,\mid\mid\,n} p^{\alpha-1}(p-1). $$
Each prime factor $p$ of $n$ contributes $p-1$ to $\phi(n)$. Since $p-1$ is even,  $\phi(n)$ is divisible by $2^k$, where $k$ equals the number of distinct prime divisors of $n$. Since $n^2+3=4m$, with $m$ odd, $k=1$ or $2$.
$\bullet$ Suppose $k=1$, and write $n=p^{\alpha}$, $p$ prime. Then eqn.$(1)$ gives
$$ p^{\alpha-1}(p-1) \mid (p^{2\alpha}+3). \quad \ldots \quad (2) $$
If $\alpha=1$, then $(p-1) \mid (p^2+3)$, and so $(p-1) \mid \big((p^2+3)-(p^2-1)\big)$. Thus, $p-1 \in \{1,2,4\}$, and $p=3$ or $5$; so $n=3,5$ are solutions.
If $\alpha>1$, then $p \mid (p^{2\alpha}+3)$, and so $p \mid 3$. This implies $p=3$, and eqn.$(2)$ gives
$$ 2 \cdot 3^{\alpha-1} \mid 3\big(3^{2\alpha-1}+1\big). $$
Since the highest power of $3$ dividing the RHS is $1$, we can only have $\alpha=2$. We note that $\phi(3^2) \mid (3^4+3)$; so $n=3^2$ is a solution.
So the three solutions in this case are $\boxed{n=3,5,3^2}$.
$\bullet$ Suppose $k=2$, and write $n=p^{\alpha}q^{\beta}$, $p,q$ primes, $\alpha \ge \beta \ge 1$. Note that since $4$ is the highest power of $2$ dividing the LHS of eqn.$(1)$, we must have $p \equiv q \equiv 3\pmod{4}$.
Now eqn.$(1)$ gives
$$ p^{\alpha-1} q^{\beta-1} (p-1)(q-1) \mid (p^{2\alpha}q^{2\beta}+3). \quad \ldots \quad (3) $$
If $\alpha=1$, then $\beta=1$, and eqn.$(3)$ gives
$$ (p-1)(q-1) \mid (p^2q^2+3). \quad \ldots \quad (4) $$
Thus, $(p-1) \mid \big((p^2q^2+3)-(p^2-1)q^2\big)=(q^2+3)$; similarly, $(q-1) \mid (p^2+3)$.
If $p=3$, this gives $(q-1) \mid 12$. Since $q-1 \equiv 2\pmod{4}$, $q>p$, we have $q=7$. Note that $\phi(3 \cdot 7) \mid (21^2+3)$; so $n=3 \cdot 7$ is a solution.
Now suppose $3<p<q$. Then $p^2+3 \equiv q^2+3 \equiv 1\pmod{3}$, so that $p \equiv q \equiv 2\pmod{3}$ since $(p-1) \mid (q^2+3)$ and $(q-1) \mid (p^2+3)$. So both $p+1$ and $q+1$ are multiples of $3$ and $4$, and hence $p,q \equiv -1\pmod{12}$.
Now suppose $\ell$ is a prime divisor of $(pq)^2+3$, $\ell>3$. Then $-3$ is a quadratic residue modulo $\ell$, and so we have
$$ \left(\frac{-1}{\ell}\right) = \left(\frac{3}{\ell}\right) = \pm 1. $$
If each is $+1$, then $\ell \equiv 1\pmod{4}$ and so $1=\left(\frac{\ell}{3}\right)$. This implies $\ell \equiv 1\pmod{3}$. Together we get $\ell \equiv 1\pmod{12}$.
If each is $-1$, then $\ell \equiv -1\pmod{4}$ and so $1=\left(\frac{\ell}{3}\right)$. Again $\ell \equiv 1\pmod{3}$, and we get $\ell \equiv 7\pmod{12}$.
Hence, $\ell \equiv 1\pmod{6}$. Since $p,q \equiv -1\pmod{12}$, $3 \nmid (p-1)$ and $3 \nmid (q-1)$. So both $p-1,q-1$ are of the form $2t$, where $t$ is a (possibly empty) product of primes of the form $6\lambda+1$.
The empty product gives $p-1=2$, and has been dealt with. Otherwise, both $p-1$ and $q-1$ are of the form $12\lambda+2$, which contradicts the fact that $p,q \equiv -1\pmod{12}$.
We conclude that there is no solution with $3<p<q$.
If $\alpha>1$, then $p$ must divide $p^{2\alpha}q^{2\beta}+3$. Hence, $p \mid 3$, and so $p=3$. Now eqn.$(3)$ gives
$$ 2(q-1)3^{\alpha-1}q^{\beta} \mid 3\big(3^{2\alpha-1}q^{2\beta}+1\big). $$
Since the highest power of $3$ dividing the RHS is $1$, we can only have $\alpha=2$. Thus,
$$ 2(q-1)q^{\beta} \mid (27q^{2\beta}+1). $$
However, $q$ divides the LHS but not the RHS, so we have no further solutions.
The only solution in this case is $\boxed{n=3 \cdot 7}$.
Therefore,
$$ \phi(n) \mid (n^2+3) \Longleftrightarrow n \in \{1,2,3,5,9,21\}. $$