-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path680C.cpp
More file actions
42 lines (40 loc) · 875 Bytes
/
680C.cpp
File metadata and controls
42 lines (40 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
long long int p;
int q;
scanf("%lld %d", &p, &q);
vector<int>v;
long long int k= p;
for (int i = 2; i <= sqrt(q); i++)
{
if(q%i==0){
v.push_back(i);
if(q/i != i){
v.push_back(q/i);
}
}
}v.push_back(q);
long long int ans = -1;
if(p%q!=0){
printf("%lld\n",p);
continue;
}
for (int i = 0; i < v.size(); i++)
{
long long int l = p;
int d = 1;
while (l%q==0){
d *= v[i];
l /= v[i];
}
ans = max(ans,l);
}
printf("%lld\n",ans);
}
}