Divisibility Exercise

Find all integers n such that n^2+n+1 is divisible by n+5 .

Solution.
Let d=n+5. Then n=d-5 and ,n^{2}+n+1=(d-5)^{2}+(d-5)+1=d^{2}-9d+21.
If n^{2}+n+1 is divisible by n+5, then d\mid(d^{2}-9d+21). Since d\mid d^{2} and d\mid 9d, it follows that d\mid 21.
Hence d is any (nonzero) divisor of 21, namely d\in{\pm1,\pm3,\pm7,\pm21}. Converting back to n=d-5 gives the solutions

n=-26,-12,-8,-6,-4,-2,2,16.