#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int nax = 1005;
int n, m, q;
struct Edge {
int to, w;
};
int gcd(int a, int b) {
while(b) {
a %= b;
swap(a, b);
}
return a;
}
vector<Edge> adj[nax];
int dist[nax][nax];
bool vis[nax][nax];
void dfs(int v, int p, int mn) {
// vis[p][v] = true;
for(Edge u : adj[v]) {
if (u.w >= mn && dist[p][u.to] < mn) {
dist[p][u.to] = max(dist[p][u.to], mn);
dfs(u.to, p, mn);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> q;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
int g = gcd(i, j);
if (g <= m) {
adj[i].push_back({j, g});
// cout << i << " " << j << " " << g << "\n";
}
}
}
for(int k = 1; k <= m; k++) {
for(int i = 1; i <= n; i++) {
dfs(i, i, k);
}
}
while(q--) {
int x, y;
cin >> x >> y;
cout << m - dist[x][y] + 1 << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
498 ms |
2800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1589 ms |
3856 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1590 ms |
8672 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1591 ms |
12352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
375 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
351 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
351 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
329 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
331 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
308 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |