Solution:
We will classify all good functions with parameter α∈Fp∖{0}. We will use = to denote equality modulo p when appropriate. Let the given statement be P(x,y). Then P(x,0) gives f(x)f(0)=2f(x) for all x∈Z. f cannot be the zero function because it does not have minimal period 2016. Therefore f(0)=2.
P(x,1) gives f(x+1)−f(1)f(x)+αf(x−1)=0. This means that f satisfies a recurrence of depth two.
We can interpret f as a function f:Z→Fp2, embedding the codomain Fp inside of Fp2. Let τ,ρ be the unique roots of t2−f(1)t+α=0 in Fp2, so that τ+ρ=f(1), τρ=α. Since α is nonzero, so are τ and ρ. Notice that f(0)=τ0+ρ0 and f(1)=τ1+ρ1. By induction up and down, we see that f(n)=τn+ρn for all n∈Z.
We can also easily check that given any value of f(1) and α with α≡0(modp), we get a unique such function. Thus there are p(p−1) total such functions, one corresponding to each quadratic t2−at+b, where b=0. If τ,ρ are the roots of the quadratic, the associated function is f(n)=τn+ρn.
Now if f is q-periodic then f(n)=f(n+q) for all n∈Z, so τn+ρn=τn+q+ρn+q for all n∈Z so
τn(1−τq)=ρn(ρq−1)
We have two cases.
Case 1. τ=ρ.
Then n=0 and n=1 above give 1=τq=ρq, and this is furthermore sufficient to be q-periodic. Thus the period of f is the minimal q such that τq=ρq=1, so the lcm of the orders of τ,ρ as elements of Fp2.
Case 2. τ=ρ.
Then we see that τ=ρ=2f(1), so they are in Fp. This automatically means that f(n)=2(2f(1))n for all n∈Z, where f(1)=0 is forced (as τρ=α). This has period dividing p−1. More specifically, the period is the order of 2f(1) as an element of Fp.
In the first case, note that the orders of τ,ρ dividing p−1 implies that τ,ρ are actually in Fp, so that we can restrict to counting recurrences f(n)=an+bn where a,b are nonzero elements of Fp.
The unordered pair {a,b} determines a+b=f(1) and ab=α, so it determines a unique f by our earlier observation. We need to count the number of such pairs with lcm(ordp(a),ordp(b))=p−1.
Recall that for d∣p−1, there are ϕ(d) elements of order d in Fp×. If a=b we need ordp(a)=p−1, so there are ϕ(p−1) functions. If S is the number of ordered pairs (a,b) with lcm(ordp(a),ordp(b))=p−1, then we see that the desired count is 2ϕ(p−1)+S (as each unordered pair {a,b} is counted twice as an ordered pair except for those with a=b).
Now let n=p−1. We are counting pairs with the lcm equal to n. The number of pairs with respective orders d1,d2 is ϕ(d1)ϕ(d2) hence our desired sum is ∑d1,d2∣n,lcm(d1,d2)=nϕ(d1)ϕ(d2). Now notice that ϕ is a multiplicative function, and the condition on the sum splits among the prime powers dividing n, so we can choose how d1,d2 behave on the prime factors of n independently. Therefore if we define
χ(n)=d1,d2∣n,lcm(d1,d2)=n∑ϕ(d1)ϕ(d2)
then χ is multiplicative. Finally, if q is prime and e≥1 we have
χ(qe)=d1,d2∣qe,lcm(d1,d2)=qe∑ϕ(d1)ϕ(d2)=2ϕ(qe)(ϕ(1)+ϕ(q)+⋯+ϕ(qe−1))+ϕ(qe)2=2qe−1(q−1)qe−1+q2e−2(q−1)2=q2e−2(q2−1)=q2e(1−q21)
This implies that χ(n)=n2∏q∣n(1−q21) by multiplicativity. Finally, our original answer is
2ϕ(p−1)+(p−1)2∏q∣p−1(1−q21)
which we now compute for p=2017. We have p−1=2016=25⋅32⋅7. Thus ϕ(p−1)=24⋅2⋅3⋅6=576 and ∏q∣2016(1−q21)=43⋅98⋅4948=4932. Thus the number of functions is
2576+4932⋅20162=2576+215⋅34=288+214⋅34=1327392