Under construction

Still being built. Things may change

The k-th Binary Decimal Number

Time limit3sMemory limit1024 MB

Summary
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 nn, the set AnA_n is defined as the set of binary decimal multiples of nn that have the smallest number of digits. If no binary decimal number is a multiple of nn, then AnA_n is the empty set.

Given a positive integer nn and a sequence of mm positive integers k1,k2,cdots,km\\{k_1, k_2, \\cdots, k_m\\}, write a program that computes the kik_i-th smallest element of AnA_n for each value kik_i (1≤i≤m1 \le i \le m) in the sequence.

Input

The first line contains two positive integers nn and mm, separated by a space. (1≤n≤1061 \le n \le 10^6, 1≤m≤1041 \le m \le 10^4)

From the second line onward, the (i+1)(i+1)-th line contains the value kik_i. (1≤i≤m1 \le i \le m, 1≤ki≤10181 \le k_i \le 10^{18})

Output

For each ii from 1 to mm, output one line. If AnA_n has at least kik_i elements, print the kik_i-th smallest element of AnA_n. Otherwise, print X.

Examples3

  1. Example 1

    Input
    27 4
    1
    2
    3
    4
    
    Expected output
    1101111111
    1111101111
    1111111101
    X
    
  2. Example 2

    Input
    17 2
    2
    1
    
    Expected output
    X
    11101
    
  3. Example 3

    Input
    903375 5
    100
    200
    300
    400
    500
    
    Expected output
    1011010111111011101101011000
    1101011111011110100110111000
    1110011111111101101101001000
    1111011110111100111001011000
    X