#P8302. [CoE R4 B/Stoi2041] 龙拳

    ID: 8936 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>模拟数学数论洛谷原创O2优化枚举洛谷月赛

[CoE R4 B/Stoi2041] 龙拳

Background

Problem Description

For nZ2n \in \mathbb{Z_{\ge 2}}, let g(n)g(n) be the largest proper divisor of nn (the largest divisor less than nn), for example, g(7)=1,g(12)=6g(7) = 1, g(12) = 6.

Define f(n)=n+g(n)f(n) = n + g(n). Let f(0)(n)=nf^{(0)}(n)=n, and for mZ0m \in \mathbb{Z_{\ge 0}} we have f(m+1)(n)=f(f(m)(n))f^{(m+1)}(n)=f(f^{(m)}(n)).

There are multiple queries. For each query, given positive integers n,kn,k, find the smallest natural number m0m_0 such that for any mm0m \ge m_0, we always have f(m)(n)f(m+k)(n)f^{(m)}(n) \mid f^{(m+k)}(n).

If such an m0m_0 does not exist, let m0=1m_0=-1.

Input Format

The first line contains a positive integer TT, the number of queries.

The next TT lines each contain two positive integers n,kn,k, representing one query.

Output Format

For each query, output one integer as the answer.

2
2 3
3 4

0
-1

Hint

Sample Explanation

When n=2,k=3n=2,k=3, m0=0m_0=0.

When n=3,k=4n=3,k=4, there is no m0m_0 that satisfies the condition.


Constraints

This problem uses bundled testdata.

  • Subtask 11 (11 point): T=k=1T=k=1.
  • Subtask 22 (1212 points): T,n,k10T,n,k \le 10.
  • Subtask 33 (2424 points): T10,n105T \le 10,n \le 10^5.
  • Subtask 44 (3636 points): T103T \le 10^3.
  • Subtask 55 (2727 points): no special constraints.

For 100%100\% of the data, it is guaranteed that 1T2×1061 \le T \le 2 \times 10^6, 2n3×1072 \le n \le 3 \times 10^7, 1k1091 \le k \le 10^9.

Translated by ChatGPT 5