Small Programming Techniques and Algorithms

For the summation of floor(n/i) from i=1 to n, we can compute it in O(sqrt(n)) time. The curve of n/x for 1 ≤ x ≤ n has non-increasing segments where floor(n/i) remains constant. For any segment [l, r], all values of floor(n/i) are equal, and r divides n. Here's an implementation: for (ll start = 1; start <= n; start++) { ll quotient = n ...

Posted on Sat, 08 Aug 2026 16:39:55 +0000 by pelegk2