← All problemsSign in

Minimize Digit Sum

CodeChefRating 2167Open on judge ↗

Let $f(n, B)$ be the sum of digits of the integer $n$ when written in base $B$. More formally, if $n = \sum\limits_{i=0}^{\infty} a_i B^i$ where $a_i$ is an integer in the range $[0, B-1]$, then $f(n, B) = \sum\limits_{i=0}^{\infty} a_i$. Given $Q$ queries, each consisting of three integers $n, l$ and $r$. Find the value of $B$ corresponding to which $f(n, B)$ is minimum for all $l \leq B \leq r

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start