Let the set D={0,1,…,p−1}, and let the polynomial f(x)=(x−1)x(x+1)=x3−x. The congruence and congruence symbol “≡” in this question refer to congruence modulo p. For k=0,1,2,3, let
Bk={b∈D∣there are exactly k elements a∈D such that f(a)≡b}.
Consider an element b in B2, i.e., there exist a1≡a2 such that f(a1)≡f(a2)≡b. In this case,
0≡(a13−a1)−(a23−a2)=(a1−a2)(a12+a1a2+a22−1)⇒a12+a1a2+a22≡1.
Thus, for a3=−a1−a2, we have a32+a3a1+a12=(a1+a2)2−(a1+a2)a1+a12≡1, so it can be deduced that f(a3)≡f(a1)≡b, by the definition of B2, a3 is congruent to one of a1,a2, so either a2≡−2a1 or a1≡−2a2, assume the former, in this case, a12+a1a2+a22≡3a12≡1, 3b≡3a13−3a1≡−2a1. When 3 is a quadratic residue modulo p, a1 has two solutions; when 3 is not a quadratic residue modulo p, a1 has no solution. Therefore, there are exactly 1+(p3) solutions for a1, and the corresponding b also has 1+(p3) solutions, i.e., ∣B2∣=1+(p3).
Obviously, ∣B1∣+2∣B2∣+3∣B3∣=∣D∣=p.
On the other hand, consider the pairs (u,v) that satisfy "f(u)≡f(v) and u≡v" (called a collision). This is equivalent to u2+uv+v2≡1 and u−v≡0. After changing variables to (x,y)≡(2u−v,2u+v) (i.e., (u,v)≡(x+y,y−x), such that (x,y) and (u,v) correspond one-to-one), it is transformed into x2+3y2≡1 and x≡0.
We consider the number of (x,y) pairs satisfying x2+3y2≡1(modp) (i.e., (3y)2≡3−3x2).
T=x=1∑p1+(p3−3x2)=p+(p−3)x=1∑p(px2−1)=p+(p−3)x=2∑p(px−1x+1)=p+(p−3)x=1∑p−1(p1+x−12)=p+(p−3)z=1∑p−1(pz+1)=p−(p−3).
The above formula uses the fact that z=x−12 traverses the complete set of residues modulo p, and that ∑k=1p(pk)=0. Among the T pairs (x,y), there are exactly 1+(p3) pairs for which x≡0 (i.e., 3y2≡1). Therefore, the number of ordered collision pairs (u,v) is
M=T−1−(p3)=p−(p−3)−1−(p3)=T−∣B2∣.
Thus, there are exactly 2M unordered collision pairs (u,v). Since the elements in B3 correspond to 3 collisions, the elements in B2 correspond to 1 collision, and the elements in B1 and B0 correspond to 0 collisions, it follows that ∣B2∣+3∣B3∣=2M.
Thus, ∣B3∣=6M−2∣B2∣, so the number of all possible residues of f(x) modulo p is
∣B1∣+∣B2∣+∣B3∣=p−∣B2∣−2∣B3∣=p−3M+∣B2∣=p−3T=32p+(p−3)=⌊32p+1⌋.
Note 1: Another way to calculate the number of solutions T is:
Consider the congruence equation x2+3y2≡z2, which is equivalent to 3y2≡z2−x2=(z+x)(z−x), having p2 solutions (y≡0 has exactly 2p−1 solutions, y≡1 has exactly p−1 solutions, and so on). The number of solutions with z≡0 is
m0=1+(p−1)[1+(p−3)],
and the number of solutions for the remaining z≡1,z≡2,...,z≡p−1 are equal (using (x,y,z)↔(kx,ky,kz) to map the solutions with z≡1 to the solutions with z≡k), each equal to T=p−1p2−m0=p−(p−3).
If one is not familiar with Legendre symbols, one can first obtain 0≤m0≤2p, and deduce that the number of solutions to x2+3y2≡1 is T∈p−1,p,p+1. The subsequent answer to this problem is p−3T, which is an integer. From this, we can still get the needed answer.
Note 2: Another interpretation of the number of solutions T=p−(p−3) is: For each y, the number of x that satisfy x2≡1−3y2 is 1+(p1−3y2), therefore
T−p=y=0∑p−1(p1−3y2)≡y=0∑p−1(1−3y2)2p−1=y=0∑p−1((−3)2p−1yp−1+⋯+1)≡(−3)2p−1(p−1)=−(p−3).