In the case n=pq, S=1+p+q+pq=(1+p)(1+q). Suppose p<q.
Let us consider possible cases.
If S=40, then (p+1)(q+1)=40. Since p+1≥3, the following cases are possible:
p+1=4,q+1=10⇒p=3,q=9⇒q is not prime.
p+1=5,q+1=8⇒p=4,q=7⇒p is not prime.
If S=41, then (p+1)(q+1)=41, since 41 is prime, there are no solutions.
If S=42, then (p+1)(q+1)=42. The options are:
p+1=3,q+1=14⇒p=2,q=13⇒n=26.
p+1=6,q+1=7⇒p=5,q=6⇒q is not prime.
So, in this case, we have a single number n=26, which satisfies the conditions.
In case n=p3, S=1+p+p2+p3. Note that if p=2, then 1+p+p2+p3=15; if p=3, 1+p+p2+p3=40; and if p≥4, 1+p+p2+p3≥85.
In this case, there is also a single number n=27, which satisfies the conditions.