Equality of sums with fractional parts of the form $\sum_{k=1}^{n}k\{\frac{mk}{n}\}$ I recently encountered the following equality ($\{\}$ denotes fractional part):
$$\sum_{k=1}^{65}k\left\{\frac{8k}{65}\right\}=\sum_{k=1}^{65}k\left\{\frac{18k}{65}\right\}$$
and found it very interesting as most of the individual summands on one side of the equation do not have a corresponding match on the other side. Investigating further, I found several other similar equalities:
$$\sum_{k=1}^{77}k\left\{\frac{9k}{77}\right\}=\sum_{k=1}^{77}k\left\{\frac{16k}{77}\right\}$$
$$\sum_{k=1}^{77}k\left\{\frac{17k}{77}\right\}=\sum_{k=1}^{77}k\left\{\frac{24k}{77}\right\}$$
$$\sum_{k=1}^{85}k\left\{\frac{7k}{85}\right\}=\sum_{k=1}^{85}k\left\{\frac{22k}{85}\right\}$$
Does anyone have any idea what general principle/pattern these arise from?
 A: Given $n$, let $a$ and $b$ be integers coprime with $n$. Then:
$$\sum_{k=1}^n k \left\{ \frac{ak}{n}\right\} = \sum_{k=1}^n k \left\{ \frac{bk}{n}\right\}$$
As Michael Stocker commented:
$$f(a,n) = \sum_{k=1}^n k \left\{ \frac{ak}{n}\right\} = \sum_{k=1}^n k  \frac{ak \mod n}{n} = \frac{1}{n}\sum_{k=1}^n k  (ak \mod n)$$
$$f(b,n) = \sum_{k=1}^n k \left\{ \frac{bk}{n}\right\} = \sum_{k=1}^n k  \frac{bk \mod n}{n} = \frac{1}{n}\sum_{k=1}^n k  (bk \mod n)$$
I've been able to prove that, as Thomas Andrews said, if $ab \equiv 1 \pmod{n}$ then $f(a,n) = f(b,n)$:
Let $k' := ak \mod n$ then $k' (bk' \mod n) = k (ak \mod n)$. Here's the proof:
$k'[b(ak \mod n) \mod n] = k'(abk \mod n) = k'(k \mod n) = k'k = k(ak \mod n)$.
Note that $\lbrace (ak \mod n) \vert 1\leq k \leq n\rbrace = \lbrace 0, 1,2\cdots ,n-1\rbrace$.
So now $$f(a,n) = \sum_{k=1}^n k \left\{ \frac{ak}{n}\right\} = \sum_{k'=1}^n k' \left\{ \frac{bk'}{n}\right\} = f(b,n)$$
Now for the cases like $f(8,65) = f(18,65)$ where $ab \not\equiv 1$ I've found that $$k(ak \mod n) - k(bk\mod n) = \\(n-k)(b(n-k)\mod n) - (n-k)(b(n-k)\mod n)$$
But so far I've been unable to caracterize the pairs $(a,b)$ with that property.
A: Here is a small GNU Maxima script to ease experimentation

    display2d : false;

    /* x rational */
    my_floor(x) := block(
        if (x >= 0) then block(
            ab : divide(ratnumer(x),ratdenom(x)),
            a : ab[1], b : ab[2],
            if (b = 0) then block(
                return(x)
            ) else block(
                return(x - b/ratdenom(x))
            )
        ) else block(
            ab : divide(ratnumer(-x),ratdenom(-x)),
            a : ab[1], b : ab[2],
            if (b = 0) then block(
                return(x)
            ) else block(
                return(x - (1-b/ratdenom(-x)))
            )
        )
    );

    /* x rational */
    my_frac(x) := x - my_floor(x);

    cz : 0; cnz : 0;
    for N : 1 thru 20 do block(
    for m1 : 1 thru 20 do block(
    for m2 : m1+1 thru 20 do block(
        mylhs : apply("+",makelist(k*my_frac(m1*k/N),k,1,N)),
        myrhs : apply("+",makelist(k*my_frac(m2*k/N),k,1,N)),
        if (mylhs - myrhs = 0) then block(
            cz : cz+1,
            print(N,m1,m2,"|",mylhs)
        ) else block(
            cnz : cnz+1
        )
    )));
    print(cz,"|",cnz);


A: [Raw data deleted.]
Defining $$f(a,n)=\sum_{k=1}^{n-1} k\left\{\frac{ka}{n}\right\}$$ it's pretty obvious that $f(a,n)+f(n-a,n)=\frac{n(n-1)}{2}$ when $(a,n)=1$. It's also true, as proven by Darth Geek, that if $ab\equiv 1\pmod n$ then $f(a,n)=f(b,n)$.
Further data leads to:

Conjecture: If $f(a,n)=f(b,n)$ then $n\mid (a-b)(ab-1)$, or, equivalently, $a+a^{-1}\equiv b+b^{-1}\pmod n$, where the inverses are taken modulo $n$. 

This would mean that the pairs $a,a^{-1}$ are the only solutions when $n$ a prime.
It is definitely not sufficient, since $a=3,b=48,n=65$ satisfies this condition.
This conjecture holds for all integers $4\leq n\leq 5000$.
$$\begin{align}f(a,n)&=\frac{a}{n}\sum_{k=1}^{n-1} k^2 - \sum_{k=1}^{n-1} k\left\lfloor\frac{ka}{n}\right\rfloor\\
&=\frac{a(n-1)(2n-1)}{6} - \sum_{k=1}^{n-1} k\left\lfloor\frac{ka}{n}\right\rfloor
\end{align}$$
Thus $f(a,n)$ is an integer if $(n,6)=1$.
