#P16065. [CSPro 32] 因子化简

[CSPro 32] 因子化简

Background

Luogu’s testdata is only for non-official communication and is not official testdata. Official judging link: https://www.cspro.org/.

Problem Description

A prime number (also called a “prime”) is a natural number greater than 11 that has no divisors other than 11 and itself.

After learning the concept of prime numbers, student P learned that any positive integer nn can be uniquely represented as a product of several prime factors. If the positive integer nn has mm distinct prime factors p1,p2,⋯ ,pmp_1, p_2, \cdots, p_m, then it can be written as: $n = p_1^{t_1} \times p_2^{t_2} \times \cdots \times p_m^{t_m}$.

Student P believes that the exponent tit_i corresponding to each prime factor reflects how important that prime factor is to nn. Now set a threshold kk. If the exponent tit_i corresponding to some prime factor pip_i is less than kk, then this prime factor is considered unimportant, and the term pitip_i^{t_i} can be removed by dividing it out from nn. Otherwise, keep the term pitip_i^{t_i}. The product of the remaining terms is the simplified value of nn. If no terms remain, then the simplified value is considered to be 11.

Write a program to process qq queries:

  • Each query contains two positive integers nn and kk, and you need to compute the simplified value of nn according to the method above.

Input Format

Read data from standard input.

The input consists of q+1q + 1 lines.

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

Each of the next qq lines contains two positive integers nn and kk, indicating a query.

Output Format

Write to standard output.

The output consists of qq lines.

Each line outputs a positive integer, indicating the result for the corresponding query.

3
2155895064 3
2 2
10000000000 10
2238728
1
10000000000

Hint

Sample Explanation

Query 1:

  • n=23×32×234×107n = 2^3 \times 3^2 \times 23^4 \times 107
  • The prime factor 33 has exponent 22, and 107107 has exponent 11. After removing these two terms from nn, the product of the remaining terms is 23×234=22387282^3 \times 23^4 = 2238728.

Query 2:

  • All terms are removed, output 11.

Query 3:

  • All terms are kept, output nn as is.

Subtasks

40%40\% of the testdata satisfies: n≤1000n \le 1000.

80%80\% of the testdata satisfies: n≤105n \le 10^5.

All testdata satisfies: 1<n≤10101 < n \le 10^{10} and 1<k,q≤101 < k, q \le 10.

Translated by ChatGPT 5