1. Define Good Integers:
Let n be a positive integer such that p∣n!+1. We call such an integer n a good integer. Note that p−1 is the largest good integer because for n≥p, n! is divisible by p, making n!+1 not divisible by p.
2. Lemma 1:
For each positive integer t, there are at most t good integers k such that k+t is also good.
Proof of Lemma 1:
Suppose p divides both (k+t)!+1 and k!+1. Then:
p∣((k+t)!+1)−(k!+1)=k!((k+1)(k+2)⋯(k+t)−1).
Since k is a good integer, gcd(p,k!)=1. Therefore:
p∣(k+1)(k+2)⋯(k+t)−1.
The right-hand side is a polynomial of degree t in k, which has at most t solutions in Fp by Lagrange's theorem. ■
3. Sequence of Good Integers:
Let n1<n2<⋯<nm=p−1 denote the set of good integers. For each 1≤j≤p, let aj denote the number of integers 1≤k≤m such that nk−nk−1=j. By Lemma 1, aj≤j for each j.
4. Sum of Differences:
We have:
a1+2a2+⋯+pap=k=1∑m(nk−nk−1)=nm−n1≤p.
We wish to maximize a1+a2+⋯+ap.
5. Lemma 2:
Suppose b1,…,bn are nonnegative real numbers such that:
b1+2b2+⋯+nbn≤nandbi≤i for all i.
Then there exists a constant c>0 such that:
b1+b2+⋯+bn≤cn2/3.
Proof of Lemma 2:
Without loss of generality, we may replace the condition with b1+2b2+⋯+nbn=n. Consider an arbitrary n-tuple (b1,…,bn) of nonnegative real numbers satisfying the given conditions. If there exist integers r<s with br<r but bs>0, then we may replace (b1,…,bn) by the tuple:
(b1′,…,bn′)=(b1,…,br−1,br+rsε,br+1,…,bs−1,bs−ε,bs+1,…),
where ε is chosen small enough that br+rsε<r and bs>ε. Then:
b1′+2b2′+⋯+nbn′=b1+2b2+⋯+nbn=n,
but the sum b1+b2+⋯+bn increases. This means that (b1,…,bn) does not achieve our maximum. In particular, our maximum is achieved when:
bj={j0if 1≤j≤t,if j≥t+2,
where t is some positive integer at most n.
Finally, observe that:
n=b1+2b2+⋯+nbn≥12+22+⋯+t2≳t3,
and hence t≲n1/3. Then:
b1+b2+⋯+bn=b1+⋯+bt+1≤1+⋯+(t+1)≲t2≲n2/3,
and so b1+⋯+bn≤cn2/3 for some constant c. ■
6. Application of Lemma 2:
Apply Lemma 2 to the sequence (a1,…,ap). Since a1+2a2+⋯+pap≤p and ai≤i, we conclude that:
a1+a2+⋯+ap≤cp2/3.
The final answer is cp2/3.