#include <bits/stdc++.h>
#define div divisores
using namespace std;
const int maxn = 1010;
int pai[maxn], peso[maxn];
int n, m, q;
int gcd(int a, int b){
return b ? gcd(b, a%b) : a;
}
void reset(){
for(int i=1;i<=n;i++)
pai[i] = i, peso[i] = 0;
}
int find(int u){
return (pai[u] == u ? u : pai[u] = find(pai[u]));
}
inline void join(int a, int b){
a = find(a);
b = find(b);
if(peso[a] == peso[b]) peso[b]++;
else if(peso[a] > peso[b]) swap(a, b);
pai[a] = b;
}
int main(){
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m >> q;
for(int i=1;i<=q;i++){
int a, b;
cin >> a >> b;
reset();
int k;
for(k=m;k>=1;k--){
for(int i=2;i*k<=n;i++)
if(find(k) != find(i*k)) join(k, i*k);
if(find(a) == find(b))
break;
}
cout << m - k + 1 << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
275 ms |
704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1568 ms |
1516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1561 ms |
2068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
2068 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
2068 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
2068 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
2068 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
2144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
2144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |