Proof. First, we show that there are infinitely many good primes. It is well-known that there are infinitely many primes p≡3(mod4). We prove that if p≡3(mod4), then p is a good prime. Let f(0)=0. Consider all quadratic residues of p, denoted as r1,r2,…,r(p−1)/2. If ri2≡rj(modp), we draw a directed edge from ri to rj. If i=j, it is considered a self-loop. Then all vertices r1,r2,…,rp−1 in this directed graph have an out-degree of 1. Moreover, for any ri, let d2≡ri(modp). Since (p−1)=−1, either d or −d (but not both) is a quadratic residue modulo p. Thus, every vertex also has an in-degree of 1. This means the directed graph is a disjoint union of cycles.
For a directed cycle ri1→ri2→⋯→ris→ri1:
- If s=2t+1 (odd), we define
f(ri1)=2u, f(ri2)=2u+4, …, f(rit+1)=2u+4t, f(rit+2)=2u+4t−2, …, f(ri2t+1)=2u+2.
- If s=2t (even), we define
f(ri1)=2u, f(ri2)=2u+4, …, f(rit+1)=2u+4t−4, f(rit+2)=2u+4t−2, …, f(ri2t)=2u+2.
Here, u is any integer. Since each cycle uses a consecutive sequence of even numbers, we can choose these numbers appropriately to ensure that the values used by different cycles do not overlap. Notice that only even numbers are used. If w is not a quadratic residue, let v=w2(modp), and define f(w)=f(v)−1. This ensures that f remains injective and satisfies ∣f(a)−f(b)∣≤2024 whenever p∣a2−b. Therefore, all primes p≡3(mod4) are good primes.
Next, we prove that there are infinitely many bad primes. It is well-known that for any positive integer n, if an odd prime p divides A2n+1 (where A is an integer), then p≡1(mod2n+1). This is because ordp(A)∣2n+1 but ordp(A)∤2n, so ordp(A)=2n+1. Thus, there are infinitely many odd primes p≡1(mod2n+1). (If there were only finitely many, let A be twice the product of these primes, which leads to a contradiction.)
Now, let p≡1(mod2100). We prove that p is a bad prime. By the existence of primitive roots, the equation x2100≡1(modp) has exactly 2100 solutions modulo p. If there exists an injective function f satisfying the problem's conditions, then for all x satisfying x2100≡1(modp) and x∈{1,2,…,p−1}, we must have ∣f(x)−f(1)∣≤2024×100. However, there are 2100 such x, while the interval [f(1)−2024×100,f(1)+2024×100] contains only 404801<2100 integers. Thus, there must be two distinct x with the same image, contradicting injectivity! Therefore, p is a bad prime.
Hence, there are infinitely many bad primes.