The k-th Binary Decimal Number
Time limit3sMemory limit1024 MB
Given n and k, find the k-th smallest binary decimal multiple of n that has the fewest digits among all such multiples, or report X if there are fewer than k.
- Level
Medium7 of 10
- Topics
- BFS, Number theory, Combinatorics
- Solved
- No attempts yet
Problem
A number is called a binary decimal number if its decimal representation consists only of the digits 0 and 1. For example, 101001 is a binary decimal number, but 102002 is not.
For a positive integer , the set is defined as the set of binary decimal multiples of that have the smallest number of digits. If no binary decimal number is a multiple of , then is the empty set.
Given a positive integer and a sequence of positive integers , write a program that computes the -th smallest element of for each value () in the sequence.
Input
The first line contains two positive integers and , separated by a space. (, )
From the second line onward, the -th line contains the value . (, )
Output
For each from 1 to , output one line. If has at least elements, print the -th smallest element of . Otherwise, print X.