TITLE: Proof that:$ \sum\limits_{n=1}^{p} \left\lfloor \frac{n(n+1)}{p} \right\rfloor= \frac{2p^2+3p+7}{6} $ where $p$ is a prime and $p \equiv 7 \mod{8}$
QUESTION [7 upvotes]: Proof that:$ \sum\limits_{n=1}^{p} \left\lfloor \frac{n(n+1)}{p} \right\rfloor= \frac{2p^2+3p+7}{6} $

where $p$  is a prime number such that $p \equiv 7 \mod{8}$ 


I tried to separate the sum into parts but it does not seems to go anywhere. I also tried to make a substitutions for $p$ ,but, I don't think it is entriely correct to call $p=7+8t$. Any ideas?

REPLY [2 votes]: $$\sum_{i=1}^p \frac{n(n+1)}p = \frac1 p \frac {p(p+1)(p+2)}3 = \frac{p^2+3p+2}3$$, and 
$$\frac{p^2+3p+2}3 - \frac{2p^2+3p+7}6 = \frac{p-1}2$$
So you are asking to prove that $$\sum_{n=1}^p \frac{n(n+1)}p - \lfloor\frac{n(n+1)}p\rfloor = \frac{p-1}2$$.
The term being summed is $\dfrac 1 p$ times the residue of $n(n+1)$ modulo $p$.
So this becomes showing $\displaystyle \sum_{n \in \Bbb F_p} (n(n+1) \pmod p) = p(p-1)/2$
Let $f(x)$ be the number of solutions to $n(n+1)=x$ in $\Bbb F_p$.
$n(n+1) = x \iff n^2 + n = x \iff (2n+1)^2 = 4x+1$, hence $\displaystyle f(x) = 1 + \binom{4x+1}p$,
and the sum becomes $\displaystyle \sum_{x=0}^{p-1} x f(x) = \sum x + \sum x \binom{4x+1}p$.
The first sum is $p(p-1)/2$, so we are left with showing that the second sum is zero.
Let us do a last rearrangement by setting $y = 1+4x$ and writing the sum as $\displaystyle \sum x(y) \binom y p $, where $x(y) = \frac 14 (y-1 + k(y)p)$ and $k(y)$ is the remainder of $y-1$ mod $4$.
Let $\displaystyle S_i = \sum_{y \equiv i \pmod 4} \binom y p$.
Since $-1$ is not a square, $S_0 = - S_3$ and  $S_1 = - S_2$.
Since $2$ is a square, $S_1 + S_3 = S_2 + S_3$ (and $S_0 + S_2 = S_0 + S_1$) hence $S_1 = S_2 = 0$.
We can rewrite the sum into $$\frac 1 4 \left(\sum y\binom y p + (3p-1)S_0 - S_1 + (p-1)S_2 + (2p-1)S_3\right) = \frac 1 4 \left(\sum y\binom y p + p(S_0  + S_2)\right)$$
Since $(-1)$ is not a square, $$\sum y \binom y p = \sum_0^{(p-1)/2} (2y - p) \binom y p$$ 
By this question, this is $$-p \sum_0^{(p-1)/2} \binom y p = -p \sum_0^{(p-1)/2} \binom {2y} p = -p(S_0 + S_2)$$