#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N=1e5+5;
int const mod=1e9+7;
set<int> com[N];
int rep[N];
set<int> qr[N];
map<pair<int,int>,int> mp;
vector<pair<int,int>> queries;
int main(){
int n,m,q;
cin>>n>>m>>q;
for (int i = 0; i < q; ++i)
{
int a,b;
cin>>a>>b;
qr[a].insert(b);
qr[b].insert(a);
queries.push_back({a,b});
}
for(int i=1;i<=n;i++){
rep[i]=i;
com[i].insert(i);
}
for(int i=m;i>=1;i--){
for(int j=2*i;j<=n;j+=i){
if(rep[i]==rep[j])
continue;
int u=rep[i],v=rep[j];
if(com[u].size()<com[v].size())
swap(u,v);
for(int c:com[v]){
// rep[c]=u;
// com[u].insert(i);
for(auto q:qr[c]){
if(mp.find({c,q})==mp.end() && com[u].find(q)!=com[u].end()){
mp[{c,q}]=i;
mp[{q,c}]=i;
}
}
}
for(int c:com[v]){
com[u].insert(c);
rep[c]=u;
}
com[v].clear();
}
}
for(auto p:queries){
cout<<mp[p]<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
11096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
14020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
184 ms |
25816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
294 ms |
33476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
163 ms |
21964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
163 ms |
22984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
249 ms |
28076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
305 ms |
33344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
380 ms |
35008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
419 ms |
38724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |