Hide

Problem H
Number Magic

Alice and Bob engage in a strategic duel called Number Magic, where Alice initially chooses a positive integer N called the starting number. The game permits two specific magic operations to be performed on a positive integer K:

  1. Say K has D digits. One operation is to add the number consisting of D 1-digits (i.e. j=0D110j) to K. For example, if K=93091 then this magic operation would add 11111 to K resulting in 104202; if K=99 then it becomes 110; if K=9 it becomes 10.

  2. If K>1, one operation is to divide K by 2 and round down. For example, if K=2 then it becomes 1, if K=13 it becomes 6.

There are Q rounds of the duel. In round i, Bob picks a target number Mi and the Alice must determine if it is possible to apply at most 32 magic operations to the starting number N in order to reach Mi. That is, Alice should find a sequence N0,N1,N2,,Nk with k32 such that N0=N and Ni can be obtained by applying a magic operation to Ni1 for each 1ik? Note, only Mi will change between rounds: N will be the same in each round.

This is a very challenging game, Alice has asked you for help!

Input

The first line of input contains two space integers, N (1N1016) and Q (1Q1000) where N is the starting number that Alice chooses and Q is the number of rounds.

Then Q lines follow, the i’th such line containing a single integer Mi (1Mi1016) indicating the target number that Bob chooses for round i

Output

Output Q lines where line i contains the text YES if it is possible to transform N into Mi using at most 32 applications of magic, otherwise line i contains the text NO.

Sample Input 1 Sample Output 1
7 2
43
28
YES
YES
Sample Input 2 Sample Output 2
74 1
18
YES
Sample Input 3 Sample Output 3
22 2
9961
1
NO
YES
Hide

Please log in to submit a solution to this problem

Log in