Under construction

Still being built. Things may change

Sum Sequence

Time limit1sMemory limit1024 MB

Summary
For a given M, decide for each query N whether N appears in the sequence B_M formed by repeatedly summing the M smallest unused positive integers.
Level

Hard8 of 10

Topics
Math, Number theory, Simulation
Solved
No attempts yet

Problem

Futsal fiend Dongwoo always gathers people around him to play futsal. Among the futsal members Dongwoo gathered were Jaewoo, Jongwoo, Hyunchul, Junhyeok, Yongmyeong, Jaehyun, Donghyun, Geunhyeong, Dohun, Minseong, Munseong, Sejun, and many others. Many of them were recruited last year, at the Ilsan futsal gathering held after the 2024 ICPC Seoul Regional, as problem setters or testers for <6th MatKor Cup:2025 Winter>.

Jaewoo received a sequence from Dohun and wants to give back a sum sequence rather than a sequence of sums. Jaewoo builds the sum sequence with the following process.

At first, the set A=Z+A=\mathbb{Z}^+ contains all positive integers. Repeat the following process 101 000 00010^{1\,000\,000} times on this set to build a new sequence BMB_M.

  1. Choose the MM smallest numbers in AA, and compute their sum SS.
  2. For each of the MM chosen numbers, if that number is in AA, remove it from AA. Also, if SS is in AA, remove SS from AA.
  3. Append SS to BMB_M.

For example, when M=3M=3, 1+2+3=61+2+3=6, 4+5+7=164+5+7=16, 8+9+10=278+9+10=27, 11+12+13=3611+12+13=36, and 14+15+17=4614+15+17=46, so B3=[6,16,27,36,46,57,66,75,⋯ ]B_3=[6, 16, 27, 36, 46, 57, 66, 75, \cdots].

Given MM and QQ queries, determine for each query whether that number is in BMB_M.

Input

The first line contains M(1≤M≤1018)M(1\le M\le 10^{18}) and Q(1≤Q≤105)Q(1\le Q\le 10^5), separated by a space. Each of the next QQ lines contains one integer N(1≤N≤1018)N(1\le N\le 10^{18}), the number to check.

Output

For each query, print 1 if the number is in BMB_M, otherwise print 0, one per line.

Examples2

  1. Example 1

    Input
    2 7
    3
    6
    49
    15
    10
    275631
    38472633
    
    Expected output
    1
    0
    1
    0
    0
    0
    1
    
  2. Example 2

    Input
    3 6
    16
    55
    57
    75
    1353
    38472657
    
    Expected output
    1
    0
    1
    1
    0
    1