Digit Sum Depth
Time limit2sMemory limit512 MB
Given N, m, and base l, find the smallest positive integer whose iterated base-l digit sum takes exactly N steps to fall below l, and output it modulo m.
- Level
Hard8 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
For a positive integer , let be the sum of the digits of written in base . Let be the smallest with , where and for .
Given , find the smallest positive integer with and print that value modulo .
Input
The input has several test cases. Each test case is one line with three integers , , (, , ).
The last line contains 0 0 0. That line is not a test case.
Output
For each test case, print one line of the form Case x: y. Here is the test case number starting at 1, and is the smallest such modulo .