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 mxN = 1e7+1;
int dp[mxN], dp2[mxN];
void solve() {
int M, Q;
cin >> M >> Q;
vector<int> primes(M);
for (auto &a : primes) cin >> a;
for (auto p : primes) {
for (int i = p; i < mxN; i += p) {
dp2[i - 1] = max(dp2[i - 1], p - 1);
}
}
for (int i = mxN - 2; i >= 0; --i) {
dp2[i] = max(dp2[i], dp2[i + 1] - 1);
}
dp[0] = 0;
for (int i = 1; i < mxN; ++i) {
dp[i] = 1e9;
dp[i] = dp[i - dp2[i]] + 1;
}
while(Q--) {
int n;
cin >> n;
int ans = dp[n];
if (ans >= 1e9) cout << "oo\n";
else cout << dp[n] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
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... |