Submission #237513

#TimeUsernameProblemLanguageResultExecution timeMemory
237513VEGAnnPictionary (COCI18_pictionary)C++14
28 / 140
1596 ms1272 KiB
#include <bits/stdc++.h> #define PB push_back using namespace std; typedef long long ll; const int N = 200100; int pr[N], n, m, q; 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 (; q; q--){ int x, y; cin >> x >> y; for (int i = 1; i <= n; i++) pr[i] = i; for (int i = m; i > 0; i--){ for (int j = i + i; j <= n; j += i) pr[get(j)] = get(i); if (get(x) == get(y)){ cout << m - i + 1 << '\n'; break; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...