The Story Behind My Codeforces Username
2024-12-25

Once upon a time, years before I joined the platform, I came across this problem:


Problem: What is the fewest number of marks that one needs to inscribe on a ruler so that any distance from 1,2,,n1,2,\ldots,n can be measured?


Since mm marks can only measure (m2)\binom{m}{2} distinct distances, we clearly need at least O(n)O(\sqrt{n}) marks to measure all distances from 11 to nn. Now if b=nb=\lceil{\sqrt{n}\rceil} and we mark the ruler at locations

{(b1),  ,  3,  2,  1,  0}{b,  2b,  3b,  ,  b2} \{-(b-1),\;\ldots,\;-3, \;-2, \;-1,\; 0 \} \cup \{b, \;2b,\;3b, \;\ldots,\; b^2\}

then all the distances up until b2+b1>nb^2+b-1 > n are represented, using only 2b=O(n)2b = O(\sqrt{n}) marks.


Therefore, the answer to this problem is asymptotically O(n)O(\sqrt{n}). And this is how I learned about Square Root Decomposition, the first topic I'd ever encounter in the vast world of programming contests.


A related concept are the golomb rulers, the smallest rulers for which all (m2)\binom m2 distances between marks are different. Though they don't necessarily need to cover all distances 1,2,,n1,2,\ldots,n, the best rulers will have most of these small distances. For instance, marking a length-1111 ruler at 00, 22, 77, 88, and 1111 gives us the pairwise distinct distances of 1,2,,91,2,\ldots,9 and 1111, which is optimal.


So, in early April 2024, I registered as "golomb," and so far, it has been a blast.