CF1444A.Division

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.

To improve his division skills, Oleg came up with tt pairs of integers pip_i and qiq_i and for each pair decided to find the greatest integer xix_i, such that:

  • pip_i is divisible by xix_i;
  • xix_i is not divisible by qiq_i.

Oleg is really good at division and managed to find all the answers quickly, how about you?

奥列格最喜欢的科目是历史和数学,而他最钟爱的数学分支是除法。

为了提升自己的除法能力,奥列格构造了 tt 对整数 pip_i 和 qiq_i,并对每一对数,他希望找出满足以下条件的最大整数 xix_i:

  • pip_i 能被 xix_i 整除;
  • xix_i 不能被 qiq_i 整除。

奥列格的除法能力非常出色,很快就求出了所有答案。你呢?

输入格式

The first line contains an integer tt (1≤t≤501 \le t \le 50) — the number of pairs.

Each of the following tt lines contains two integers pip_i and qiq_i (1≤pi≤10181 \le p_i \le 10^{18}; 2≤qi≤1092 \le q_i \le 10^{9}) — the ii-th pair of integers.

第一行包含一个整数 tt(1≤t≤501 \le t \le 50)—— 表示数对的个数。

接下来的 tt 行,每行包含两个整数 pip_i 和 qiq_i(1≤pi≤10181 \le p_i \le 10^{18};2≤qi≤1092 \le q_i \le 10^{9})—— 表示第 ii 个数对。

输出格式

Print tt integers: the ii-th integer is the largest xix_i such that pip_i is divisible by xix_i, but xix_i is not divisible by qiq_i.

One can show that there is always at least one value of xix_i satisfying the divisibility conditions for the given constraints.

输出 tt 个整数:第 ii 个整数是满足以下条件的最大 xix_i:pip_i 能被 xix_i 整除,但 xix_i 不能被 qiq_i 整除。

可以证明,在给定约束条件下,总存在至少一个满足整除条件的 xix_i 值。

输入输出样例

  • 输入#1

    3
    10 4
    12 6
    179 822

    输出#1

    10
    4
    179

说明/提示

For the first pair, where p1=10p_1 = 10 and q1=4q_1 = 4, the answer is x1=10x_1 = 10, since it is the greatest divisor of 1010 and 1010 is not divisible by 44.

For the second pair, where p2=12p_2 = 12 and q2=6q_2 = 6, note that

  • 1212 is not a valid x2x_2, since 1212 is divisible by q2=6q_2 = 6;
  • 66 is not valid x2x_2 as well: 66 is also divisible by q2=6q_2 = 6.

The next available divisor of p2=12p_2 = 12 is 44, which is the answer, since 44 is not divisible by 66.

对于第一组数,其中 p1=10p_1 = 10 且 q1=4q_1 = 4,答案为 x1=10x_1 = 10,因为它是 1010 的最大因数,且 1010 不能被 44 整除。

对于第二组数,其中 p2=12p_2 = 12 且 q2=6q_2 = 6,注意到:

  • 1212 不是合法的 x2x_2,因为 1212 能被 q2=6q_2 = 6 整除;
  • 66 同样不是合法的 x2x_2:66 也能被 q2=6q_2 = 6 整除。

p2=12p_2 = 12 的下一个可用因数是 44,即为答案,因为 44 不能被 66 整除。

输入解题思路,AI测评打分。不知道怎么写?

首页