#P4901. Reorder Formation Beauty
Reorder Formation Beauty
Reorder Formation Beauty
Problem Description:
In class , the instructor was not impressed with the current formation of the students, so he decided to rearrange the order.
The process is as follows:
1. All students are arranged in a line in increasing order of their student numbers (from to ).
2. Then, repeatedly, from the current line, he picks students at positions corresponding to the Fibonacci sequence: (1-indexed). That is, in each iteration, he extracts the students standing in the , , , , , , ... positions of the current line until no valid position can be chosen. These extracted students form one row (preserving their order) and are appended as the next row in the final formation.
For example, if there are 10 students, the process is illustrated below (bold indicates the picked students):
Initial line: 1 2 3 4 5 6 7 8 9 10
After removal, remaining: 4 6 7 9 10
Iteration 2: current line: 4 6 7 9 10
After removal, remaining: 9
Iteration 3: current line: 9
The final formation is:
- Row 1: 1 2 3 5 8
- Row 2: 4 6 7 10
- Row 3: 9
The beauty of a row is defined as the total number of prime factors (with multiplicity) in the prime factorization of the product of all student numbers in that row. (Note: For the number , the count is because does not have any prime factors.)
You are given test cases. For each test case, you are provided with two positive integers (the number of students) and . Your task is to determine the beauty of the -th row in the final formation. If the final formation contains fewer than rows, output .
inputFormat
Input Format:
The first line contains an integer , the number of test cases.
Each of the next lines contains two space‐separated integers and , where is the number of students and is the row number (1-indexed) to query.
outputFormat
Output Format:
For each test case, output the beauty of the -th row. If the formation has fewer than rows, output .
sample
3
10 2
10 3
10 4
7
2
-1
</p>