determine $\left(\sum\limits_{g=1}^{p-1} g \times ((ag \mod p))\right) \bmod p^2$ Let $p$ be a prime, and let $((x))$ be the least positive residue of $x$ modulo $p$. For $a \in \{1, 2, ..., p-1\}$, consider $f(a) = \sum\limits_{g=1}^{p-1} g \times ((a g))$.
Does the following hold: $f(a)=f(b)$ if and only if $a=b$ or $a=b^{-1} \bmod p$？ Furthermore, can we determine $f(a) \bmod p^2$？

First,

$f(a) = \frac{1}{2} \sum_{g=1}^{p-1} [ (g + a(g))^2 - g^2 - a(g)^2 ] = \frac{1}{2} \sum_g (g + a(g))^2 - \sum_g g^2$ .

Next, note that $g + a(g) = c(g)$ or $c(g) + p$ for $a \neq p-1$, where $c = a+1 ($mod $p)$, and $g + a(g) = p$ for $a=p-1$.
So for $a=p-1$,

$f(a) = \frac{p^2(p-1)}{2} - \frac{(p-1)p(2p-1)}{6} = \frac{(p-1)p(p+1)}{6}$.  

For $a<p-1$,

$f(a) = \frac{1}{2} \sum_g c(g)^2 + \frac{1}{2} \sum_{c(g)<g} (2c(g) p + p^2) - \frac{(p-1)p(2p-1)}{6} $
  $ = \frac{1}{2} \sum_{c(g)<g} (2c(g) p + p^2) - \frac{(p-1)p(2p-1)}{12}$.

Now, I believe that for $c\neq 1$, $c(g)<g$ exactly half the time (as $c(-g) = p-c(g)$).  So we have in the latter case

$ f(a) = \sum_{c(g)<g} c(g) p + \frac{p^2(p-1)}{4} - \frac{(p-1)p(2p-1)}{12} = \sum_{c(g)<g} c(g) p + \frac{(p-1)p(p+1)}{12}$.

Edited: That's as far as I got.
