The Elf's Sword
Time limit1sMemory limit128 MB
For each input n, find the smallest k such that the digits 0 through 9 all appear across the multiples n, 2n, ..., kn.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Bit manipulation, Brute force
- Solved
- No attempts yet
Problem
The elves of Middle-earth believe that some numbers matter more than others. They believe that when they forge a sword from an amount of metal, choosing its thickness according to the rule below yields an extraordinarily powerful blade.
Given a non-negative integer , consider the sequence
Writing out every number in this sequence one after another, you must find the smallest for which every digit from to appears at least once.
Elrond, Lord of Rivendell, wants a program that does this for him. Given the amount of metal , write a program that finds the ideal thickness satisfying the rule above.
Input
The input consists of several lines, each containing a single integer . Each satisfies . The input continues line by line until end of file.
Output
For each value , print on its own line the smallest such that the digits through all first appear across the sequence .