-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
61 lines (60 loc) · 1.14 KB
/
E.cpp
File metadata and controls
61 lines (60 loc) · 1.14 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;
map<int,int> A,B;
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
void primeFactors(int x, int index)
{
for(int i = 2; i * i <= x; ++i){
while(x % i == 0){
if(index == 1){
A[i]++;
} else{
B[i]++;
}
x /= i;
}
}
if(x > 1){
if(index == 1){
A[x]++;
} else{
B[x]++;
}
}
}
int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int t;
cin>>t;
while(t){
A.clear(); B.clear();
int m,n;
cin>>m>>n;
primeFactors(m,1);
primeFactors(n,2);
long long a = 1;
for(map<int,int>::iterator it = A.begin(); it != A.end(); ++it) {
if(A[it->first] > B[it->first]){
a*=binpow(it->first, it->second);
}
}
for(map<int,int>::iterator it = B.begin(); it != B.end(); ++it) {
if(B[it->first] > A[it->first]){
a*=binpow(it->first, it->second);
}
}
cout<<a<<"\n";
t--;
}
return 0;
}