Removal of Multiples

AtCoder
IDarc197_c
Time4000ms
Memory256MB
Difficulty
Let $S$ be the set of all positive integers. Process $Q$ queries in order. The $i$\-th query gives you an integer $A_i$ not less than $2$ and a positive integer $B_i$, so perform the following two steps in order. 1. Remove from $S$ all elements that are multiples of $A_i$. 2. Print the $B_i$\-th smallest element of $S$. It can be shown that under the given constraints, $S$ contains at least $B_i$ elements at this point. ## Constraints * $1\le Q\le 10^5$ * $2\le A_i\le 10^9$ * $1\le B_i\le 10^5$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $Q$ $A_1$ $B_1$ $\vdots$ $A_Q$ $B_Q$ [samples]
Samples
Input #1
5
5 10
6 1
6 10
9 10
123456789 111
Output #1
12
1
14
16
178

When the elements of $S$ are listed in ascending order, the beginning of the list evolves as follows.

*   Initially, $S=\lbrace 1,2,3,4,5,6,7,8,9,10,\ldots\rbrace$.
*   The first query removes multiples of $5$, resulting in $S=\lbrace1,2,3,4,6,7,8,9,11,12,\ldots\rbrace$.
*   The second query removes multiples of $6$, resulting in $S=\lbrace1,2,3,4,7,8,9,11,13,14,\ldots\rbrace$.
*   The third query removes multiples of $6$, resulting in $S=\lbrace1,2,3,4,7,8,9,11,13,14,\ldots\rbrace$.
*   The fourth query removes multiples of $9$, resulting in $S=\lbrace1,2,3,4,7,8,11,13,14,16,\ldots\rbrace$.
*   The fifth query removes multiples of $123456789$, resulting in $S=\lbrace1,2,3,4,7,8,11,13,14,16,\ldots\rbrace$.
API Response (JSON)
{
  "problem": {
    "name": "Removal of Multiples",
    "description": {
      "content": "Let $S$ be the set of all positive integers. Process $Q$ queries in order. The $i$\\-th query gives you an integer $A_i$ not less than $2$ and a positive integer $B_i$, so perform the following two ste",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc197_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Let $S$ be the set of all positive integers.\nProcess $Q$ queries in order. The $i$\\-th query gives you an integer $A_i$ not less than $2$ and a positive integer $B_i$, so perform the following two ste...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments