Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.