#P11747. 「TPOI-1A」鞋子特大号

    ID: 11208 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学贪心O2优化素数判断,质数,筛法

「TPOI-1A」鞋子特大号

Description

Given a number xx, you can perform the following operations multiple times until no longer possible:

  • Choose a number yy satisfying 1y<x1 \le y < x and gcd(x,y)1\gcd(x, y) \neq 1, then replace xx with gcd(x,y)\gcd(x, y).

There are TT queries of two types:

  • 1 x: Given xx, find the maximum number of operations that can be performed on xx;
  • 2 q: Given qq, find the smallest xx such that the maximum number of operations on xx is exactly qq.

Input Format

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

Each of the next TT lines contains a query in the format 1 x or 2 q.

Output Format

For each query, output one integer as the answer.

2
1 2310
2 6
4
128

Hint

Explanation for Sample #1

For 1 2310, one possible operation sequence is:

  • Choose y=1890y = 1890, then x=gcd(2310,1890)=210x = \gcd(2310, 1890) = 210;
  • Choose y=84y = 84, then x=gcd(210,84)=42x = \gcd(210, 84) = 42;
  • Choose y=18y = 18, then x=gcd(42,18)=6x = \gcd(42, 18) = 6;
  • Choose y=2y = 2, then x=gcd(6,2)=2x = \gcd(6, 2) = 2.

No further operations can be performed, so the result is 44.

It can be proven that no method allows more than 44 operations.


For 2 6, it can be proven that no number smaller than 128128 can perform exactly 66 operations.

Constraints

This problem uses bundled tests. You must pass all test cases in a subtask to receive points.

Subtask Special Constraints Points
0 Sample 0
1 T2T \le 2, 2x1002 \le x \le 100, q5q \le 5 40
2 T105T \le 10^5, x103x \le 10^3, q25q \le 25 30
3 No special constraints

For 100%100\% data: 1T1051 \le T \le 10^5, 1x1061 \le x \le 10^6, 1q621 \le q \le 62.

Translated by DeepSeek R1