How many ways to write numbers as sums of squares?
Python 3, 125 bytes



n,d=eval(input())
W=[1]+[0]*n
exec("W=[sum(-~(j&gt;0)*W[i-j*j]for j in range(int(i**.5)+1))for i in range(n+1)];"*d)
print(W[n])


Try it online!

Finishes the last testcase in 0.078 s. Naive complexity is O(d n 2).