CF1444A.Division
普及/提高-
通过率:0%
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 t pairs of integers pi and qi and for each pair decided to find the greatest integer xi , such that:
- pi is divisible by xi ;
- xi is not divisible by qi .
Oleg is really good at division and managed to find all the answers quickly, how about you?
输入格式
The first line contains an integer t ( 1≤t≤50 ) — the number of pairs.
Each of the following t lines contains two integers pi and qi ( 1≤pi≤1018 ; 2≤qi≤109 ) — the i -th pair of integers.
输出格式
Print t integers: the i -th integer is the largest xi such that pi is divisible by xi , but xi is not divisible by qi .
One can show that there is always at least one value of xi satisfying the divisibility conditions for the given constraints.
输入输出样例
输入#1
3 10 4 12 6 179 822
输出#1
10 4 179
说明/提示
For the first pair, where p1=10 and q1=4 , the answer is x1=10 , since it is the greatest divisor of 10 and 10 is not divisible by 4 .
For the second pair, where p2=12 and q2=6 , note that
- 12 is not a valid x2 , since 12 is divisible by q2=6 ;
- 6 is not valid x2 as well: 6 is also divisible by q2=6 .
The next available divisor of p2=12 is 4 , which is the answer, since 4 is not divisible by 6 .