luogu#P4901. 排队
排队
Background
The formation of Class CYJian... is it a trapezoid??
$\color{white}\text{How many girls can there be in an informatics competition class??}$
Problem Description
The instructor thinks that Class CYJian’s formation is not very good-looking very bad-looking, so the instructor decides to rearrange it.
First, the instructor asks all students to line up in increasing order of student ID in a single row. Then, each time, the instructor pulls out the -th people (roughly the Fibonacci sequence) from the current queue, until no one can be pulled out. These selected people form a new row, which is placed behind the previous row.
For example, if there are students, it goes like this (bold means the currently selected person):
- $\bm{\color{red}1}\ \bm{\color{red}2}\ \bm{\color{red}3}\ 4 \ \bm{\color{red}5} \ 6 \ 7 \ \bm{\color{red}8} \ 9\ 10$, after taking them away: ;
- $\bm{\color{red}4}\ \bm{\color{red}6}\ \bm{\color{red}7}\ 9\ \bm{\color{red}10}$, after taking them away: ;
- .
The final formation looks like this:
- Row 1: ;
- Row 2: ;
- Row 3: .
(Of course, a formation arranged by the instructor has to be said to look good...)
Now we define the “beauty” of a row as the number of prime factors in the prime factorization of the product of all student IDs in that row. In particular, since cannot be decomposed into any prime factors, its count is .
For example, for the second row, $4 \times 6 \times 7 \times 10=1680=2 \times 2 \times 2 \times 2 \times 3 \times 5 \times 7$, so the beauty of this row is .
There are classes in the grade, and each class must be arranged once. For the -th class, you are given the number of students and a positive integer . You need to find the beauty of the -th row after arranging the formation for the -th class.
In particular, if the formation does not have a -th row, output .
Input Format
The first line contains a positive integer .
The next lines each contain two positive integers and .
The meanings of the variables are described in the statement.
Output Format
Output lines, each containing one positive integer, representing the required beauty.
3
10 2
12 2
1 2
7
7
-1
Hint
This problem uses bundled testdata.
- Subtask 1 (30pts): , ;
- Subtask 2 (30pts): , , ;
- Subtask 3 (40pts): , , .
The testdata does not guarantee the existence of a test point where all outputs are .
Translated by ChatGPT 5