luogu#P4901. 排队

    ID: 3880 远端评测题 666ms 40MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>树状数组O2优化前缀和Fibonacci 数列

排队

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 1,2,3,5,8,13,1, 2, 3, 5, 8, 13, \cdots-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 1010 students, it goes like this (bold means the currently selected person):

  1. $\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: 4 6 7 9 104\ 6\ 7\ 9\ 10;
  2. $\bm{\color{red}4}\ \bm{\color{red}6}\ \bm{\color{red}7}\ 9\ \bm{\color{red}10}$, after taking them away: 99;
  3. 9\bm{\color{red}9}.

The final formation looks like this:

  • Row 1: 1 2 3 5 81\ 2\ 3\ 5\ 8;
  • Row 2: 4 6 7 104\ 6\ 7\ 10;
  • Row 3: 99.

(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 11 cannot be decomposed into any prime factors, its count is 00.

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 77.

There are TT classes in the grade, and each class must be arranged once. For the ii-th class, you are given the number of students NiN_i and a positive integer KiK_i. You need to find the beauty of the KiK_i-th row after arranging the formation for the ii-th class.

In particular, if the formation does not have a KiK_i-th row, output 1-1.

Input Format

The first line contains a positive integer TT.

The next TT lines each contain two positive integers NiN_i and KiK_i.

The meanings of the variables are described in the statement.

Output Format

Output TT 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): Ki=1K_i = 1, 1Ni,T10001 \le N_i, T \le 1000;
  • Subtask 2 (30pts): 1Ki1001 \le K_i \le 100, 1Ni100001 \le N_i \le 10000, 1T50001 \le T \le 5000;
  • Subtask 3 (40pts): 1Ki100001 \le K_i \le 10000, 1Ni5×1061 \le N_i \le 5 \times 10^6, 1T1061 \le T \le 10^6.

The testdata does not guarantee the existence of a test point where all outputs are 1-1.

Translated by ChatGPT 5