Here is the link to the problem https://www.spoj.com/problems/NASIO/. I can’t find any pattern or formula. Please help me.
Turns out that a linear combination works.