Let $a_d$ be the number of non-negative integer solutions $(a, b)$ to $a + b = d,$ where $a \equiv b \pmod{n}$ for a fixed $n\in\Bbb{Z}^+$. Consider the generating function $M(t) = a_0 + a_1t + a_2t^2 + \cdots.$ Consider $$P(n)=\lim_{t\rightarrow 1}\left(nM(t)-\frac{1}{(1-t)^2}\right)$$ Then $P(n), n\in\Bbb{Z}^+$ is a polynomial in $n$, so we can extend its domain to include all real numbers while having it remain a polynomial. Find $P(0)$.
Answer: $-\frac{1}{12}$
Source: Berkeley Math Tournament, 2017.
My attempt: Clearly, it is infeasible to use non-integral $n$ in finding the generating function, so I started listing out the values of $a_d$ for different values of $n$. I found some patterns regarding specific values of $d$ and $n$. For example, that when $n=d,$ then $a_d = 2$ if $d$ is odd, or $3$ if even. However, there was no clear general formula for general $n$ nor $d$.
I also noticed that the answer is the "value" given to the divergent series $\sum_i i,$ which could play a role in this solution, as $\frac{1}{(1-t)^2}=1+2t+3t^2+\cdots.$ However, I was not able to make any progress through this method either.
How would one approach this problem with a better method?
For each $n$ and $d$, partition the set of solutions $(a, b)$ according to the common remainder modulo $n$ and write
$$ a_{d,r} = \text{[# of solutions of $a+b = d$ with $a \equiv b \equiv r$ (mod $n$)]}$$
for $r \in \{0, \cdots, n-1\}$. Then
$$ a_{d,r} = \begin{cases} k + 1, & \text{if } d = nk +2r \text{ for some } k \in \mathbb{Z}_{\geq 0} \\ 0, & \text{otherwise} \end{cases} $$
So it follows that
\begin{align*} M(t) &= \sum_{d=0}^{\infty} a_d t^d = \sum_{d=0}^{\infty} \sum_{r=0}^{n-1} a_{d,r} t^d = \sum_{r=0}^{n-1} \sum_{k=0}^{\infty} (k+1) t^{nk+2r} = \frac{1 + t^n}{(1 - t^2)(1 - t^n)} \end{align*}
Now writing $t = 1-s$ and plugging $t^n = 1 - \binom{n}{1}s + \binom{n}{2}s^2 - \binom{n}{3}s^3 + \mathcal{O}(s^4)$ above, we check that
$$ nM(t) = \frac{1}{s^2} + \frac{n^2-1}{12} + \mathcal{O}(s). $$
(I managed to compute it by brutal force, but it will be nice if there is an elegant way of dealing with this.) Therefore $P(n) = \frac{n^2-1}{12}$ and hence $P(0) = -\frac{1}{12}$.