1. Lemma 1: For any integer n and any non-integer real number a, we have ⌊a⌋+⌊n−a⌋=n−1.
2. Since p is a prime number of the form 4k+1, it is known that −1 is a quadratic residue modulo p. Thus, there exists an integer λ such that λ2≡−1(modp).
3. Since p∤λ (because otherwise, we would have λ2≡0(modp), contradicting λ2≡−1(modp)), multiplication with λ is a permutation of the nonzero residues modulo p. Define a function L from {1,2,…,p−1} to {1,2,…,p−1} by letting L(i) be the remainder of λi upon division by p. This function L is a permutation of {1,2,…,p−1}.
4. We have:
i=1∑p−1(⌊p2i2⌋−2⌊pi2⌋)=i=1∑p−1(⌊p2(L(i))2⌋−2⌊p(L(i))2⌋)
5. For every i∈{1,2,…,p−1}, both integers i2 and 2i2 are coprime with p. Since L(i)≡λi(modp), we have:
i2+(L(i))2≡i2+(λi)2=(1+λ2)i2≡(1+(−1))i2=0(modp)
Hence, pi2+(L(i))2 is an integer. Applying Lemma 1 to n=pi2+(L(i))2 and a=pi2, we obtain:
⌊pi2⌋+⌊pi2+(L(i))2−pi2⌋=pi2+(L(i))2−1
Equivalently,
⌊pi2⌋+⌊p(L(i))2⌋=pi2+p(L(i))2−1
6. Since 2⋅pi2+(L(i))2 is an integer, while p2i2 is a non-integer, applying Lemma 1 to n=2⋅pi2+(L(i))2 and a=p2i2, we obtain:
⌊p2i2⌋+⌊2⋅pi2+(L(i))2−p2i2⌋=2⋅pi2+(L(i))2−1
Equivalently,
⌊p2i2⌋+⌊p2(L(i))2⌋=p2i2+p2(L(i))2−1
7. Now, we compute:
i=1∑p−1(⌊p2i2⌋−2⌊pi2⌋)=21(i=1∑p−1(⌊p2i2⌋−2⌊pi2⌋)+i=1∑p−1(⌊p2(L(i))2⌋−2⌊p(L(i))2⌋))
Using the fact that L is a permutation:
=21i=1∑p−1((⌊p2i2⌋+⌊p2(L(i))2⌋)−2(⌊pi2⌋+⌊p(L(i))2⌋))
Using the results from steps 5 and 6:
=21i=1∑p−1((p2i2+p2(L(i))2−1)−2(pi2+p(L(i))2−1))
Simplifying:
=21i=1∑p−11=21(p−1)=2p−1
The final answer is 2p−1