Skip to main content

Exact Digit-Sum Counts

Challenge on lesson: Checkpoint — Digit Sums

CHALLENGE
Difficulty: advanced+25 XP

**Problem.** Each line: L R K (read until EOF). Print one integer per line: the count of x in [L, R] whose digit sum is exactly K. **Constraints:** 1 ≤ q ≤ 20000; 1 ≤ L ≤ R ≤ 10^18; 1 ≤ K ≤ 162. Per query: a 19-position walk with a digit-sum budget. The DP table is rebuilt per query — still microseconds.

Back to lesson: Checkpoint — Digit Sums