The solutions are P(n)=1 and P(n)=2snk−n for 0≤s≤3 and k≥1, excluding P(n)=0.
Firstly, we denote Q(n)=P(n)+n. We then have Q(n)>n for all n>N. Note that the condition can be rewritten as
nQ(n)−n+(Q(n)−n)n≡0(modQ(n))
nQ(n)−n+(−n)n≡0(modQ(n))
Let Q(0)=a0. Assume for the sake of contradiction that a0=0 and let n>N be an odd positive integer such that (a0,n)=1. Notice that (Q(n),n)=1, since if some prime p divides both n and Q(n), it would also divide a0, contradiction. Therefore we have
nn(nQ(n)−2n−1)≡0(modQ(n))⟹nQ(n)−2n−1≡0(modQ(n)),
that is
nQ(n)−2n≡1(modQ(n))(1)
Let p∣Q(n) be an odd prime (we know that p doesn't divide n). It follows that ordp(n)∣Q(n)−2n. Let n0>N be any odd integer. By the Chinese remainder theorem there exists an integer m>N such that
m≡n(modp)
m≡n0(modp−1).
Therefore, p∣Q(m). Since n0 is odd and p∤n, it follows that m is odd and p∤m. Therefore we can conclude that (in a similar fashion as we have done for n):
mQ(m)−2m≡1(modp),
implying ordp(m)∣Q(m)−2m. Since m≡n(modp) and m≡n0(modp−1), it follows that ordp(n)∣Q(n0)−2n0.
Therefore
ordp(n)∣Q(m)−2m,
for all odd m>M, but due to the periodicity of the polynomial Q modulo ordp(n), this in fact means that the above holds for any odd integer m. Now we have that
ordp(n)∣gcd(Q(1)−2,Q(3)−6,…,Q(2i+1)−2(2i+1),…).
Denote the previous gcd with G. Let p∣G be an odd prime. It follows that p∣Q(p)−2p, implying p∣a0. Let k be a large enough positive integer. Then vp(Q(a0k)−2a0k)=vp(a0). Therefore vp(G)≤vp(a0) and so it follows that G∣2ta0 for some integer t≥0.
Coming back to our original n we get that
nG≡1(modp).
From (1) and Lifting The Exponent lemma it follows that
vp(nQ(n)−2n−1)=vp((nG)GQ(n)−2n−1)=vp(nG−1)+vp(GQ(n)−2n)≥vp(Q(n)).
As p∣Q(n) and p∤n, we get vp(GQ(n)−2n)=0.
If 2∣Q(n) Lifting The Exponent lemma for p=2 yields v2(nQ(n)−2n−1)=v2(n2−1)+v2(Q(n)−2n)−1≥v2(Q(n)). If 4∣Q(n), it follows that 2∤Q(n)−2n, yielding v2(n2−1)≥v2(Q(n)). If 2∤Q(n), v2(n2−1)≥v2(Q(n)) still holds.
If 2∣Q(n), it follows that 2∣G, and we get vp(nG−1)≥vp(Q(n)) for all primes p∣Q(n), implying Q(n)∣nG−1 (2).
As G is independent of n, we get
Q(n)∣nG−1(2)
for every odd integer n>N such that (a0,n)=1.
We say that a polynomial with integer coefficients is *primitive* if the greatest common divisor of its coefficients is 1.
Lemma. Let P(x),Q(x)∈Z[x] be primitive such that Q(n)∣P(n) for infinitely many positive integers n. Then there exists a polynomial F(x)∈Z[x] such that P(x)=Q(x)F(x).
Proof. By the polynomial division algorithm there exist polynomials F(x),R(x)∈Q[x] such that P(x)=Q(x)F(x)+R(x) and deg(R(x))<deg(Q(x)). Dividing the expression by Q(x) yields
Q(x)P(x)=F(x)+Q(x)R(x).
Let n1,n2,… be a sequence of positive integers such that Q(ni)∣P(ni) and let P(ni)=diQ(ni) for di∈Z, for all i∈N. Let D be the least common multiple of the denominators of the coefficients of F(x). Then we can write F(ni)=Dfi and Q(ni)R(ni)=ri for fi∈Z,ri∈Q. We get the following equation for every i:
di=Dfi+riDdiD−fi=ri.
As limi→∞ri=0, there has to exist a large enough positive integer j such that 0<∣rj∣<D1. Therefore R(x)≡0 and P(x)=Q(x)F(x). We are left to prove that F has integer coefficients.
Let a be the greatest common divisor of the numerators of the coefficients of F(x) and let b be the least common multiple of the denominators of the coefficients of F(x). We can assume (a,b)=1. Therefore F(x)=baF1(x) for some primitive polynomial F1(x)∈Z[x]. Now we get abP(x)=Q(x)F1(x). Since abP(x) is a polynomial with integer coefficients and (a,b)=1, it follows that a divides all coefficients of P(x). Therefore a=1 (since P is primitive).
As Q(x) and F1(x) are primitive, bP(x) is primitive by Gauss' lemma. Therefore b=1 and F(x)∈Z[x], as desired. □
Let Q(x)=dQ1(x), where d is a positive integer (possibly d=1) and Q1(x)∈Z[x] is primitive. Assume there exists an odd prime p∣d and let k≡1(modp) be an even integer such that
k>N. Then kQ(k)−k+(−k)k≡2(modp), so p=2, which is a contradiction. Therefore d=2l for some integer l≥0.
Let P1(x)=xG−1. Since Q1(n)∣P1(n) for infinitely many positive integers n and P1(x),Q1(x) are primitive, by the above lemma there exists a polynomial F(x)∈Z[x] such that P1(x)=Q1(x)F(x). In particular, −1=P1(0)=Q1(0)F(0), so Q1(0) is either 1 or −1. Therefore a0 is either 2l or −2l.
Let n>N be an even positive integer. If p∣Q(n) and p∣n, it follows that p=2. Additionally, v2(Q(n))=v2(d)=l. The original condition yields
2l(nQ(n)−2n+1)≡0(modQ(n))
nQ(n)−2n≡−1(modQ1(n))
n2(Q(n)−2n)≡1(modQ1(n))
Let p∣Q1(n) be an odd prime (p∤n). Picking n0 divisible by p−1 such that n0≡n(modp) yields
na0≡−1(modp).
If a0<0, i.e. a0=−∣a0∣, then
n∣a0∣+1=n−a0+1=na0na0+1≡0(modp)
In either case we have
n∣a0∣≡−1(modp)
n2l≡−1(modp).
Therefore ordp(n)=2l+1. Using Lifting The Exponent lemma analogously as before (without the case p=2 as 2∤Q1(n)), we get:
vp(n2(Q(n)−2n)−1)=vp((n2l+1)2l+12(Q(n)−2n)−1)=vp(n2l+1−1)+vp(2l+12(Q(n)−2n)).
Since vp(2l+12(Q(n)−2n))=0 (because p∣Q1(n) so p∣Q(n) and p∤n), we get that vp(n2(Q(n)−2n)−1)=vp(n2l+1−1)≥vp(Q1(n)) and so:
n2l+1≡1(modQ1(n))
(n2−1)(n2+1)≡0(modQ1(n))
n2l≡−1(modQ1(n)),
where the last equation holds because (n2−1,Q1(n))=1 (since any prime p that divides Q1(n) also divides n2+1, and p is odd).
Thus Q1(n)∣n2+1 for all even positive integers n>N. As Q1(x) and x2+1 are primitive, by the lemma there exists a polynomial F1(x)∈Z[x] such that x2+1=Q1(x)F1(x). Since x2+1 is known to be irreducible and Q1(x) is eventually positive, it must hold that Q1(x)=x2+1.
We return to odd values of n once again. If l≥1, we obtain G=2 (it is immediate for l>1 and for l=1 it follows from G∣Q1(1)).
Let n>N be an odd positive integer. Divisibility (2) yields
n2≡1(mod2ln2l+2l),
Therefore l=0 and Q(x)=x+1, which is easily seen to be a solution to the problem (it gives P(x)=1).
Now assume a0=0. Let Q(x)=xR(x) for some R(x)∈Z[x]. The original condition after cancelling n rewrites as
R(n)∣nn−1(nnR(n)−2n+(−1)n).
Assume there exists an even integer n>N and a prime p∣R(n) such that p∤n. Then p∣nnR(n)−2n+1. Let n0>N be an even integer such that p−1∣n0 and n0≡n(modp). It follows that p∣n0n0R(n0)−2n0+1 implying p∣2, which is false since n is even. (3)
Let R(x)=xk−1G(x) for some G(x)∈Z[x] such that G(0)=0 and k≥1. If G(x) is non-constant, by Schur's theorem there are infinitely many primes p dividing G(2mp) for some mp∈N. For large enough such primes p (and thus also 2mp), we have p∤G(0) and thus p∤2mp, which is impossible by (3).
Therefore G(x)≡c for some constant c. It follows from (3) and eventual positivity of Q(x) that c=2s for some integer s≥0, that is Q(x)=2s⋅xk.
We have
nQ(n)−n+(−n)n≡0(mod2snk).
However, if s≥4, let n≡3(mod16) then, Q(n)−n≡5(mod8),
35+(−3)3≡8(mod16),
which is a contradiction. Therefore, s≤3.
We will show that all pairs (s,k) with 3≥s≥0 and k≥1 except for s=0,k=1 satisfy the problem's conditions (s=0 and k=1 fails since we need to have Q(n)>n for n>N).
If n is even, 2snk∣nn−1 for large enough positive integers n.
If n is odd, nk∣nn−1 for large enough positive integers n and it remains to prove that 2s∣n2snk−2n−1. For s=0 the divisibility is obvious and for s≥1 we have that n2snk−2n=n2(2s−1nk−n)≡1(mod8), implying the claim.
Finally, Q(n)>n is obviously satisfied for all such s,k and the result follows.