# Formula for $\sum i\lfloor i x\rfloor$

Let $N,a,b$ be positive integers with $a$ and $b$ coprime to each other.

I can sum up $\sum\lfloor ia/b\rfloor$ (for $i$ from $1$ till $N$) by counting lattice points in a right triangle. This sum can be computed recursively in $O(\log(\max(N,a,b)))$ time.

Is there a similar way to compute $\sum i (i \lfloor a/b\rfloor)$? I am solving some problems for a competition and being computing this sum will simplify my calculations greatly.

-
The sum in the title is not the sum in the body. Which one do you really want? – Gerry Myerson Aug 8 '12 at 5:44