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;
const int NMAX = 100010, VMAX = 10000000;
int prime[NMAX + 10];
int lower[VMAX + 10];
int dist[VMAX + 10];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int m, q;
cin >> m >> q;
while (m--) {
int x;
cin >> x;
for (int i = 0; i <= VMAX; i += x)
lower[i] = x;
}
int act = 0, until = 0, next = 0;
for (int i = 0; i <= VMAX; i++) {
if (i > until)
until = next, act++;
if (until < i)
break;
dist[i] = act;
if (lower[i])
next = max(next, i + lower[i] - 1);
}
while (q--) {
int x;
cin >> x;
if (dist[x])
cout << dist[x] << '\n';
else
cout << "oo\n";
}
return 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... |