Denote by R(n) the number of red numbers in {1,2,…,n}, i.e., R(n)=nr(n). Similarly, denote by B(n) and b(n)=B(n)/n the number and proportion of blue numbers in {1,2,…,n}, respectively. Notice that B(n)+R(n)=n and b(n)+r(n)=1. Therefore, the statement of the problem does not change after swapping the colors.
Arguing indirectly, for every a∈{1,2,…,p−1} choose some positive integer na such that r(na)=a/p and, hence, R(na)=ana/p. Clearly, p∣na, so that na=pma for some positive integer ma, and R(na)=ama. Without loss of generality, we assume that m1<mp−1, as otherwise one may swap the colors. Notice that
ma≤pN<4p2−1for all a=1,2,…,p−1.
The solution is based on a repeated application of the following simple observation.
Claim. Assume that ma<mb for some a,b∈{1,2,…,p−1}. Then
mb≥bamaandmb≥p−bp−ama.
Proof. The first inequality follows from bmb=R(nb)≥R(na)=ama. The second inequality is obtained by swapping colors.
Let q=(p−1)/2. We distinguish two cases.
Case 1: All q numbers m1,m2,…,mq are smaller than mp−1.
Let ma be the maximal number among m1,m2,…,mq; then ma≥q≥a. Applying the Claim, we get
mp−1≥p−(p−1)p−ama≥(p−q)q=4p2−1
which contradicts (1).
Case 2: There exists k≤q such that mk>mp−1. Choose k to be the smallest index satisfying mk>mp−1; by our assumptions, we have 1<k≤q<p−1.
Let ma be the maximal number among m1,m2,…,mk−1; then a≤k−1≤ma<mp−1. Applying the Claim, we get
mk≥kp−1mp−1≥kp−1⋅p−(p−1)p−ama≥kp−1⋅(p−k+1)(k−1)≥kk−1⋅(p−1)(p−q)≥21⋅2p2−1
which contradicts (1) again. □