이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MX = (int)1e7;
int n, q, sieve[MX + 1], dp[MX + 1];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> q;
for(int i = 0;i < n;i ++) {
int x; cin >> x;
for(int j = x;j <= MX;j += x) {
sieve[j] = x;
}
sieve[0] = x;
}
int ptr = 0;
for(int i = 1;i <= MX;i ++) {
while(ptr < i && (ptr + sieve[ptr] <= i || dp[ptr] == INT_MAX)) ptr ++;
if(ptr == i) dp[i] = INT_MAX;
else dp[i] = dp[ptr] + 1;
}
while(q --) {
int x;
cin >> x;
if(dp[x] == INT_MAX) {
cout << "oo\n";
} else {
cout << dp[x] << '\n';
}
}
return 0;
}
// OUTPUT in new line.
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |