Sum Sequence
Time limit1sMemory limit1024 MB
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 contains all positive integers. Repeat the following process times on this set to build a new sequence .
- Choose the smallest numbers in , and compute their sum .
- For each of the chosen numbers, if that number is in , remove it from . Also, if is in , remove from .
- Append to .
For example, when , , , , , and , so .
Given and queries, determine for each query whether that number is in .
Input
The first line contains and , separated by a space. Each of the next lines contains one integer , the number to check.
Output
For each query, print 1 if the number is in , otherwise print 0, one per line.