This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
const int MXV = 1e7;
vi facs[MXV+2];
int ans[MXV+2], curVal[MXV+2];
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q; cin >> n >> q;
vi primes(n);
for_(i, 0, n) cin >> primes[i];
for (int i: primes) for (int j = i; j <= MXV; j += i) facs[j].push_back(i);
multiset<int> vals;
for (int i: primes) vals.insert(0);
for_(i, 1, MXV+1) {
for (auto p: facs[i]) vals.erase(vals.find(curVal[p]));
if (vals.size()) ans[i] = *vals.begin()+1;
else ans[i] = -1;
for (auto p: facs[i]) vals.insert(curVal[p] = ans[i]);
}
for_(x, 0, q) {
int k; cin >> k;
if (ans[k] == -1) cout << "oo";
else cout << ans[k];
cout << endl;
}
return 0;
}
Compilation message (stderr)
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:29:11: warning: unused variable 'i' [-Wunused-variable]
29 | for (int i: primes) vals.insert(0);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |