Problem 120 of Project Euler is back in the very mathy part of the questions. Or at least the part where I have been able to find a pretty mathy solution for the problem. It reads

Letrbe the remainder when (a-1)^{n}+ (a+1)^{n}is divided bya^{2}.

For example, ifa= 7 andn= 3, thenr= 42: 6^{3}+ 8^{3}= 728 42 mod 49. And asnvaries, so too willr, but fora= 7 it turns out thatr_{max}= 42.

For 3 ≤a≤ 1000, find ∑r_{max}.