#FT0000056. Xóa các bội số (Removal of Multiples)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xóa các bội số (Removal of Multiples)
Removal of Multiples
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Initially, is the infinite set of all positive integers . Each query gives . First remove permanently all positive multiples of from . Then list the surviving elements in increasing order and print the one with one-based rank .
Deletions accumulate and are never undone. Repeatedly deleting multiples of the same divisor makes no additional changes. The requested survivor is always guaranteed to exist.
Input
- Line 1: integer , the query count.
- Next lines: integers specifying the divisor to remove and the survivor rank to report.
Output
Print lines; line is the -th smallest surviving positive integer after query .
Subtasks
Subtask 1 (20 points):
- ; and for all .
Subtask 2 (30 points):
- ; and for all .
Subtask 3 (50 points):
- ; and for all .
Examples
Examples 1
Input
5
5 10
6 1
6 10
9 10
123456789 111
Output
12
1
14
16
178
Explanation
After deleting multiples of 5, the first ten survivors are , so print 12. Deleting multiples of 6 still leaves 1 as the smallest. Repeating the same deletion changes nothing; rank 10 is then 14. Removing multiples of 9 changes rank 10 to 16. Removing multiples of 123456789 cannot affect the earliest 111 surviving integers, whose 111th value is 178.
Examples 2
Input
3
2 5
3 5
2 1
Output
9
13
1
Explanation
Removing even numbers leaves , giving 9 at rank five. Next remove multiples of 3, leaving , giving 13 at rank five. Deleting even numbers again changes nothing; the smallest survivor is still 1.