Let $p=8k+7$ be a prime number, prove that:
$$\sum_{k=1}^{p-1} \left\{ \frac{2T(k)}{p}\right\} = \sum_{k=1}^{p-1} \left\{ \frac{k}{p}\right\}$$
, where $T(k)$ is the $k-$th Triangular number and $\{\frac{k}{p}\}$ is the decimal part of $\frac{k}{p}$.
It's fairly easy to notice that the RHS is equal to $\frac{p-1}{2}$, as all the fractions are less than 1, but I'm having troubles with the LHS. It's easy to notice that the terms are symmetric wrt the $\frac{p-1}{2}$ term, but that's all I found. I tried writing $2T(n) = n(n+1) = n^2 + n = (n+1)^2 - (n+1)$, but none of this helped me.
Also it's easy to notice that: $\{\frac{i}{p}\} = \frac{x}{p}$, where $x$ is the remainder when $i$ is divided by $p$. I tried a lot of examples, but I can't see a correlation between these numbers. Also as the sum of the $x$'s is less than $p^2$ I tried working modulo $p^2$ and proving that their sum is equal to $\frac{p(p-1)}{2}$, but again to no avail.
In fact I can't make use of the fact that $p$ is of the given form, as it seems that for primes other than those from the given form the identity doesn't hold.
This problem seems to be tied with how the squares are distributed when you split $\{1 \ldots p-1\}$ in $8$.
First, $2T(n) = n^2+n = (n+\frac 12)^2- \frac 14$ (remember that modulo $p$, $\frac 12 = \frac{p+1}2$ and $\frac 14 = \frac{p+1}8$).
Since every nonzero square / triangular number not equal to $-\frac 14$ is obtained twice, the difference between the two sums is the difference between the sum of the nonzero squares (translated by $-\frac 14$) and the sum of the nonsquares (also translated).
Split $(\Bbb Z/p \Bbb Z)^*$ in $8$ parts, $A_0 = \{1 \ldots \frac{p-7}8\}$,
$A_i = \{i\frac{p+1}8 \ldots (i+1)\frac{p+1}8-1\}$ for $i=1 \ldots 6$, and
$A_7 = \{7\frac{p+1}8 \ldots p-1 \}$.
$A_1$ and $A_7$ have $\frac {p-7}8$ elements, and the other $6$ have $\frac {p+1}8$ elements (so one more), for a total of $\frac{2p-14+6p+6}8 = p-1$.
Let $R_i$ be the squares residues in $A_i$, $N_i = A_i \setminus R_i$ be the nonresidues, and if $R$ if any of those sets, denote $\#S$ and $S(R)$ the cardinal and the sum (not modulo $p$) of $R$ respectively.
We have $\# R_i + \# N_i = \# A_i = (p-7)/8$ or $(p+1)/8$ according to $i$,
and $S(R_i) + S(N_i) = S(A_i)$ which can also be explicitly computed (but we won't need it)
The LHS is $- \frac 14$ plus twice the sum of the squares translated by $-\frac{p+1}4$. So if a square $s$ is in a $R_i$ for $i>1$ it contributes by $s- \frac{p+1}4$, and if it is in a $R_i$ for $i \le 1$ it contributes by $s+\frac{3p-1}4$.
And so the LHS is $\frac{3p-1}4 + 2\sum S(R_i) + (\#R_0+\#R_1)\frac{3p-1}2 - (\#R_2+\ldots+\#R_7)\frac{p+1}2$
The RHS is the sum of everyone so it is $\sum S(R_i) + \sum S(N_i)$.
Now, we use that $p = 7 \pmod 8$, which means in terms of squares, that $-1$ is not a square and that $2$ is a square.
Therefore, multiplication by $-1$ is a bijection between $A_i$ and $A_{7-i}$, and it switches squares with nonsquares.
This implies, about the sums, that $S(R_i) + S(N_{7-i}) = p\# R_i$ for $i=0\ldots 7$.
Summing those $8$ equations we can rewrite the RHS as $p \sum \# R_i$
Substracting it from the LHS you get their difference
$\Delta = \frac{3p-1}4 + 2\sum S(R_i) + (\#R_0+\#R_1)\frac{p-1}2 - (\#R_2+\ldots+\#R_7)\frac{3p+1}2$
As for the cardinals, we get $\# R_i = \# N_{7-i}$ for $i=0\ldots 7$.
Combining this with the knowledge about $\# A_i$, we have $\# R_0 + \# R_7 = (p-7)/8$, and $\# R_1 + \# R_6 = \# R_2 + \# R_5 = \# R_3 + \# R_4 = (p+1)/8$
Next, multiplication by $2$ is a bijection between $A_i \cup A_{i+4}$ and $A_{2i} \cup A_{2i+1}$ that keeps squares and nonsquares.
About the sums, we get :
$ 2S(R_i) + 2S(R_{4+i})-p\#R_{4+i} = S(R_{2i}) + S(R_{2i+1})$ for $i=0 \ldots 3$
Summing those $4$ equations gives $\sum S(R_i) = p (\# R_4 + \ldots + \#R_7)$
Plugging this in $\Delta$ we get $\Delta = \frac{3p-1}4 + (\#R_0+\#R_1+\#R_4+ \ldots + \#R_7)\frac{p-1}2 - (\#R_2+\#R_3)\frac{3p+1}2 $
Now, for cardinals, we get $\# R_i + \# R_{4+i} = \# R_{2i} + \# R_{2i+1}$ for $i=0 \ldots 3$, which can be summarized as $\#R_1 = \#R_4, \#R_2 + \#R_3 = \#R_4 + \#R_5, \#R_6 = \# R_3$
Using the previous equations we obtain $\#R_1 = \# R_2 = \#R_4$ and $\# R_3 = \# R_5 = \# R_6$, (and that the sum of those two quantities is $\frac{p+1}8$)
And so $\Delta = \frac{3p-1}4 + ((\#R_0+\#R_7)+2(\#R_1+\#R_3))\frac{p-1}2 - (\#R_1+\#R_3)\frac{3p+1}2 $
$= \frac{3p-1}4 + (\#R_0+\#R_7)\frac{p-1}2 - (\#R_1+\#R_3)\frac{p+3}2 $
$= \frac{3p-1}4 + \frac{(p-7)(p-1)}{16} - \frac{(p+1)(p+3)}{16}$
$= \frac{3p-1}4 + \frac{-12p+4}{16} = 0$