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?


Solution 1:

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.