Different Digits
Time limit1sMemory limit128 MB
For each n below 65536, find the smallest positive multiple of n whose decimal form uses the fewest distinct digits.
- Level
Hard8 of 10
- Topics
- BFS, Dynamic programming, Number theory, Math
- Solved
- No attempts yet
Problem
Given a positive integer , find a positive integer that is a multiple of and, when written in decimal, contains the fewest distinct digits. If several such share this minimum number of distinct digits, output the smallest one.
For example, contains three distinct digits: , , and .
Input
The input contains at most test cases. Each test case is a single line holding one positive integer (). There are no blank lines between test cases. A line containing a single terminates the input and is not processed.
Output
For each test case, print on its own line. If more than one qualifies, print the smallest. Do not print blank lines between test cases.