#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 200100;
vector<int> qr[N];
int pr[N], n, m, q, x[N], y[N], L[N], R[N], mid[N];
int get(int x) { return (pr[x] == x ? x : pr[x] = get(pr[x])); }
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m >> q;
for (int i = 0; i < q; i++){
cin >> x[i] >> y[i];
L[i] = 1; R[i] = m;
}
bool was = 1;
while (was){
was = 0;
for (int i = 0; i < q; i++)
if (L[i] < R[i]){
mid[i] = (L[i] + R[i]) >> 1;
qr[m - mid[i] + 1].PB(i);
was = 1;
}
for (int i = 1; i <= n; i++)
pr[i] = i;
for (int i = m; i > 1; i--){
for (int j = i + i; j <= n; j += i)
pr[get(j)] = get(i);
if (sz(qr[i])) {
for (int nm : qr[i])
if (get(x[nm]) == get(y[nm]))
R[nm] = mid[i];
else L[nm] = mid[i] + 1;
qr[i].clear();
}
}
}
for (int i = 0; i < q; i++)
cout << L[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1587 ms |
5376 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1583 ms |
6016 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1584 ms |
9204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1595 ms |
10556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1575 ms |
7476 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1581 ms |
8820 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1574 ms |
9516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1597 ms |
8564 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1587 ms |
9012 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1584 ms |
9716 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |