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>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MAXN 20000001
typedef long long ll;
using namespace std;
ll dp[MAXN + 10], p[100001], max_divide[MAXN + 10], to[MAXN + 10];
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
FOR(i, 0, n) cin >> p[i];
FOR(i, 0, n) for (int j = p[i]; j <= MAXN; j += p[i]) max_divide[j] = p[i];
ll mn = MAXN - 1;
for (int i = MAXN - 1; i > 0; i--) {
mn = min(mn, i + 1 - max_divide[i + 1]);
to[i] = mn;
}
FOR(i, 1, MAXN) if (to[i] == i) dp[i] = INT_MAX;
else dp[i] = dp[to[i]] + 1;
FOR(i, 0, q) {
int x;
cin >> x;
if (dp[x] >= INT_MAX)
cout << "oo\n";
else
cout << dp[x] << '\n';
}
return 0;
}
Compilation message (stderr)
brunhilda.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
#pragma GCC Optimize("O3")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |