AtCoder Regular Contest 197 (Div. 2)
C
Removal of Multiples
AtCoder
⌀ 1505
原题
← BD →
翻译中…

Problem Statement

翻译中…

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

翻译中…

Output

翻译中…

Print $Q$ lines. The $i$-th line should contain the $B_i$-th smallest element of $S$ after removing all multiples of $A_i$ from $S$.

翻译中…

样例

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$.
题目信息
题号
arc197_c
时间限制
4 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。