Let p be a prime with p∣d. We know that p∣ain+a1⋅a2⋯an for all i. If ∃i such that p∣ai, then p∣a1⋅a2⋯an. Since p∣ajn+a1⋅a2⋯an for all j, we find p∣aj for all j, which contradicts to the hypothesis.
Thus we consider the case p∤ai for all i, i.e. p∤a1⋅a2⋯an. We have the n congruences
a1n≡−a1⋅a2⋯an(modp),a2n≡−a1⋅a2⋯an(modp),…,ann≡−a1⋅a2⋯an(modp)
and by multiplying them, we obtain
(a1⋅a2⋯an)n≡(−1)n⋅(a1⋅a2⋯an)n≡−(a1⋅a2⋯an)n(modp)
which yields p=2.
This shows that d must be a power of 2. Suppose, now, that 4∣d. Clearly, a1,a2,…,an must be all odd. We consider two cases
1. If a1⋅a2⋯an≡3(mod4), then ∃i such that ai≡3(mod4) then ain+a1⋅a2⋯an≡3+3≡2(mod4) which contradicts with 4∣d.
2. If a1⋅a2⋯an≡1(mod4), then ∃i such that ai≡1(mod4) then ain+a1⋅a2⋯an≡1+1≡2(mod4) which also contradicts with 4∣d. (In both cases, we made use of 3n≡3(mod4).)
Therefore, d=1 or d=2. If a1,a2,…,an are all odd, then d must be even, hence d=2. If some of a1,a2,…,an are even and some of them odd, then d must be odd, hence d=1. As such, both of these values are realized.