#P10515. 转圈
转圈
Problem Description
Little likes spinning in circles.
He has a circle that is evenly divided into cells. Magically, is a prime number. On the -th cell, there is a number written as . He is now standing on the first cell.
Next, he will look at the number under his feet, then move forward by that many cells. He will keep repeating this.
Find the number of distinct cells that Little has stepped on in the end. Since Little has many circles, he will ask you many times.
Input Format
The first line contains a positive integer , representing the number of queries.
For each query, one line contains two positive integers .
Output Format
For each query, output one line with one positive integer, representing the number of cells that have been stepped on.
6
5 2
11 10
17 12
23 8
31 12
9999901 114514
4
2
4
11
30
16260
Hint
Sample Explanation
Take the first query as an example. The cell indices that Little visits in order are , so the number of distinct cells stepped on is .
Constraints
- For of the testdata, , .
- For another of the testdata, .
- For the remaining of the testdata, there are no special properties.
For all testdata, , . It is guaranteed that is prime.
Translated by ChatGPT 5