atcoder#ABC228D. [ABC228D] Linear Probing
[ABC228D] Linear Probing
Score : points
Problem Statement
There is a sequence with terms. Initially, every term is .
Process queries in order. The -th query is described by an integer such that or , and another integer , as follows.
- If , do the following in order.1. Define an integer as . 2. While , keep adding to . We can prove that this process ends after finite iterations under the Constraints of this problem. 3. Replace the value of with .
- If , print the value of at that time.
Here, for integers and , denotes the remainder when is divided by .
Constraints
- There is at least one such that .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
For each query with , print the response in one line. It is guaranteed that there is at least one such query.
4
1 1048577
1 1
2 2097153
2 3
1048577
-1
We have , so the first query sets .
In the second query, initially we have , for which , so we add to . Now we have , so this query sets .
In the third query, we print .
In the fourth query, we print .
Note that, in this problem, is a constant and not given in input.