Hide

Problem E
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. $\sum _{j=0}^{D-1} 10^ j$) 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 $M_ i$ 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 $M_ i$. That is, Alice should find a sequence $N_0, N_1, N_2, \ldots , N_ k$ with $k \leq 32$ such that $N_0 = N$ and $N_ i$ can be obtained by applying a magic operation to $N_{i-1}$ for each $1 \leq i \leq k$? Note, only $M_ i$ 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$ ($1 \leq N \leq 10^{16})$ and $Q$ $(1 \leq Q \leq 1000$) 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 $M_ i$ $(1 \leq M_ i \leq 10^{16}$) 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 $M_ i$ 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

Please log in to submit a solution to this problem

Log in