Number Magic

시간 제한3초메모리 제한2048 MB

요약
고정된 시작 수 N에서 현재 자릿수만큼의 1로 이루어진 수를 더하거나 2로 나눈 몫을 취하는 연산을 32번 이하로 써서 각 목표 수 M에 도달할 수 있는지 판정한다.
난이도

어려움10점 중 8점

유형
백트래킹, BFS, 수학
정답자
아직 제출이 없습니다

문제

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

  1. Say KK has DD digits. One operation is to add the number consisting of DD 11-digits (i.e. ∑_j=0D−110j\sum\_{j=0}^{D-1}{10^j}) to KK. For example, if K=93091K=93091 then this magic operation would add 1111111111 to KK resulting in 104202104202; if K=99K=99 then it becomes 110110; if K=9K=9 it becomes 1010.
  2. If K>1K>1, one operation is to divide KK by 22 and round down. For example, if K=2K=2 then it becomes 11, if K=13K=13 it becomes 66.

There are QQ rounds of the duel. In round ii, Bob picks a target number M_iM\_i and the Alice must determine if it is possible to apply at most 3232 magic operations to the starting number NN in order to reach M_iM\_i. That is, Alice should find a sequence N_0,N_1,N_2,…,N_kN\_0,N\_1,N\_2,\dots ,N\_k with k≤32k≤32 such that N_0=NN\_0=N and N_iN\_i can be obtained by applying a magic operation to N_i−1N\_{i-1} for each 1≤i≤k1≤i≤k? Note, only M_iM\_i will change between rounds: NN will be the same in each round.

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

입력

The first line of input contains two space integers, NN (1≤N≤10161≤N≤10^{16}) and QQ (1≤Q≤10001≤Q≤1000) where NN is the starting number that Alice chooses and QQ is the number of rounds.

Then QQ lines follow, the ii’th such line containing a single integer M_iM\_i (1≤M_i≤10161≤M\_i≤10^{16}) indicating the target number that Bob chooses for round ii.

출력

Output QQ lines where line ii contains the text YES if it is possible to transform NN into M_iM\_i using at most 3232 applications of magic, otherwise line ii contains the text NO.

예제3

  1. 예제 1

    입력
    7 2
    43
    28
    
    예상 출력
    YES
    YES
    
  2. 예제 2

    입력
    74 1
    18
    
    예상 출력
    YES
    
  3. 예제 3

    입력
    22 2
    9961
    1
    
    예상 출력
    NO
    YES