First assume n is a prime number. Thus φ(n)=n−1∣n2+3=(n−1)(n+1)+4, implying n−1∣4. We deduce that n=2,3 or 5.
From now on, assume n is composite and set n=∏i=1kpiαi, where k is the number of distinct prime divisors of n. Since n≥3, φ(n) is even. In particular, the condition φ(n)∣n2+3 shows that n is odd and so the pi's are all odd. It follows that
2k∣φ(n)=i=1∏kpiαi−1(pi−1).
So n2+3 is divisible by 2k implying that k≤2. Moreover, if αi≥2 then pi∣φ(n), so pi∣n2+3, forcing pi=3. In this case, 9∤n2+3 and 9∤φ(n). This shows that αi=2. Our discussion shows that if the composite n≥3 satisfies the problem then n=32=9 or n=9p, or n=pq for some odd primes p,q. Of course, n=9 is a solution of our problem.
- Suppose n=9p. Then φ(n)=6(p−1) and n2+3=81(p−1)(p+1)+84. Therefore, 3(p−1)∣84, or equivalently p−1∣28. It follows that p=5 or p=29. But in both cases, we have 8∣φ(n), contradiction.
- Suppose n=pq, where p,q are odd primes. First, consider the case q=3 (the case p=3 is of course similar). Then φ(n)=2(p−1) so n2+3=9(p−1)(p+1)+12. It follows that 2(p−1)∣12, and p−1∣6, implying p=3 or p=7. In this case we obtain a new solution n=pq=3×7=21 of our problem.
Now, suppose p,q>3. Thus, 3∤n2+3 so 3∤(p−1)(q−1). This shows that p,q≡2(mod3). Since (p−1)(q−1)∣p2q2+3=(p2−1)(q2−1)+p2+q2+2 so (p−1)(q−1)∣p2+q2+2. Set
p2+q2+2=k(p−1)(q−1),
where k is a positive integer. Set p=2x+1, q=2y+1, then the above equation reads x2+y2+x+y+1=kxy, or equivalently,
x2−(ky−1)x+y2+y+1=0.
By a Vieta jumping technique, we deduce that k=5. Thus, we have
5(p−1)(q−1)=p2+q2+2.
But then p≡q≡2(mod3) and the left hand side is ≡2(mod3), while the right hand side is ≡1(mod3), contradiction.
Therefore, all numbers satisfy the given condition are n∈{1,2,3,5,9,21}.