Solution:
Answer: 1−np+1p−1+(p+1)2p2(p2n−1)
In the solution all polynomials are taken modulo p. Call a polynomial nice if it is monic with nonzero constant coefficient. We can associate each recurrence relation with a polynomial: associate
cnai+n+cn−1ai+n−1+…+c1ai+1+c0ai=0
with
cnxn+cn−1xn−1+…+c1x+c0.
Let Di be the set of mod-p recurrences {ak}k≥0 where i is the least integer so that {ak}k≥0 has degree i, and let di=∣Di∣.
Let Sn be the set of pairs ({ak}k≥0,P) where {ak}k≥0 is a mod-p recurrence, and P is a nice polynomial associated to a recurrence relation of degree at most n satisfied by {ak}k≥0. To find dn generally, we count the number of elements in Sn in two ways.
On the one hand, for each sequence {ak}k≥0 in Di, there exist pn−i polynomials P such that ({ak}k≥0,P)∈S. Indeed, {ak}k≥0 satisfies any recurrence relation associated with a polynomial multiple of P. When j=i there is just one nice degree j polynomial that is a multiple of P, P itself. For j>i, there are (p−1)pj−i−1 nice polynomials of degree j that are multiples of P, namely QP where Q is a nice polynomial of degree j−i. (There are p choices for the coefficients of x,…,xj−i−1 and p−1 choices for the constant term.) So the number of nice polynomial multiples of degree at most n is
1+j=i+1∑n(p−1)pj−i−1=1+(p−1)(p−1pn−i−1)=pn−i
Hence
∣Sn∣=i=0∑ndipn−i
On the other hand, given a monic polynomial P of degree i, there are pi recurrences {ak}k≥0 such that ({ak}k≥0,P)∈S, since a0,…,ai−1 can be chosen arbitrarily and the rest of the terms are determined. Since there are (p−1)pi−1 nice polynomials of degree i=0 (and 1 nice polynomial for i=0), summing over i gives
∣Sn∣=1+i=1∑n(p−1)p2i−1
Now clearly d0=1. Setting (1) and (2) equal for n and n+1 give
i=0∑n+1dipn+1−ii=0∑ndipn−i⟹i=0∑ndipn+1−i=1+(p−1)i=1∑n+1p2i−1=1+(p−1)i=1∑np2i−1=p+(p−1)i=1∑np2i
Subtracting (4) from (3) yields:
dn+1=1−p+(p−1)i=1∑2n+1(−1)i+1pi=(p−1)i=0∑2n+1(−1)i+1pi=(p−1)2i=0∑np2m=(p−1)2(p2−1p2n+2−1)=p+1(p−1)(p2n+2−1)
Thus the answer is
i=0∑ndi=1+p+1p−1i=1∑n(p2i−1)=1+p+1p−1(−n+p2⋅p2−1p2n−1)=1−np+1p−1+(p+1)2p2(p2n−1)