#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e5+5, INF = 2e9+9;
int m, Q;
int dp[10000005];
int mxmod[20000005];
vector<int> primes;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> m >> Q;
for (int i = 0; i < m; i++) {
int p; cin >> p;
primes.push_back(p);
}
sort(primes.begin(),primes.end());
int maxPrime = primes.back();
for (int i = 1; i < maxPrime; i++) {
dp[i] = 1;
}
for (int p: primes) {
for (int i = p; i <= 20000000; i += p) {
mxmod[i-1] = max(mxmod[i-1],p-1);
}
}
for (int i = 20000000; i >= maxPrime; i--) {
if (mxmod[i] == 0) mxmod[i] = mxmod[i+1] - 1;
}
for (int i = maxPrime; i <= 10000000; i++) {
dp[i] = INF;
dp[i] = min(dp[i],1+dp[i-mxmod[i]]);
}
/*
for (int i = 1; i <= 50; i++) {
cout << i << ": " << dp[i] << '\n';
}
*/
while (Q--) {
int qi; cin >> qi;
if (dp[qi] == INF) cout << "oo\n";
else cout << dp[qi] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
192 ms |
117752 KB |
Output isn't correct |
2 |
Incorrect |
255 ms |
117704 KB |
Output isn't correct |
3 |
Incorrect |
242 ms |
117752 KB |
Output isn't correct |
4 |
Incorrect |
204 ms |
117772 KB |
Output isn't correct |
5 |
Incorrect |
266 ms |
117836 KB |
Output isn't correct |
6 |
Incorrect |
191 ms |
117752 KB |
Output isn't correct |
7 |
Incorrect |
228 ms |
117780 KB |
Output isn't correct |
8 |
Incorrect |
244 ms |
117880 KB |
Output isn't correct |
9 |
Incorrect |
300 ms |
117776 KB |
Output isn't correct |
10 |
Incorrect |
344 ms |
117752 KB |
Output isn't correct |
11 |
Incorrect |
349 ms |
117748 KB |
Output isn't correct |
12 |
Correct |
208 ms |
117752 KB |
Output is correct |
13 |
Incorrect |
545 ms |
117784 KB |
Output isn't correct |
14 |
Correct |
545 ms |
117880 KB |
Output is correct |
15 |
Incorrect |
290 ms |
117752 KB |
Output isn't correct |
16 |
Incorrect |
253 ms |
117752 KB |
Output isn't correct |
17 |
Incorrect |
293 ms |
117836 KB |
Output isn't correct |
18 |
Incorrect |
229 ms |
117992 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
257 ms |
117832 KB |
Output isn't correct |
2 |
Correct |
255 ms |
118256 KB |
Output is correct |
3 |
Incorrect |
697 ms |
118216 KB |
Output isn't correct |
4 |
Incorrect |
365 ms |
117880 KB |
Output isn't correct |
5 |
Incorrect |
565 ms |
118204 KB |
Output isn't correct |
6 |
Incorrect |
258 ms |
117880 KB |
Output isn't correct |
7 |
Incorrect |
259 ms |
117936 KB |
Output isn't correct |
8 |
Incorrect |
385 ms |
117692 KB |
Output isn't correct |
9 |
Incorrect |
568 ms |
118256 KB |
Output isn't correct |
10 |
Incorrect |
672 ms |
118132 KB |
Output isn't correct |
11 |
Incorrect |
677 ms |
118024 KB |
Output isn't correct |
12 |
Incorrect |
479 ms |
117880 KB |
Output isn't correct |
13 |
Incorrect |
260 ms |
117880 KB |
Output isn't correct |
14 |
Incorrect |
354 ms |
117864 KB |
Output isn't correct |
15 |
Incorrect |
569 ms |
118136 KB |
Output isn't correct |
16 |
Correct |
250 ms |
118348 KB |
Output is correct |
17 |
Incorrect |
603 ms |
117880 KB |
Output isn't correct |
18 |
Incorrect |
687 ms |
118296 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
665 ms |
118276 KB |
Output isn't correct |
2 |
Incorrect |
841 ms |
118136 KB |
Output isn't correct |
3 |
Incorrect |
771 ms |
118272 KB |
Output isn't correct |
4 |
Incorrect |
450 ms |
118008 KB |
Output isn't correct |
5 |
Incorrect |
324 ms |
118688 KB |
Output isn't correct |
6 |
Incorrect |
570 ms |
118140 KB |
Output isn't correct |
7 |
Incorrect |
535 ms |
118508 KB |
Output isn't correct |
8 |
Incorrect |
565 ms |
118248 KB |
Output isn't correct |
9 |
Incorrect |
618 ms |
118148 KB |
Output isn't correct |
10 |
Incorrect |
511 ms |
117844 KB |
Output isn't correct |
11 |
Incorrect |
513 ms |
118092 KB |
Output isn't correct |
12 |
Incorrect |
545 ms |
118008 KB |
Output isn't correct |
13 |
Incorrect |
815 ms |
118392 KB |
Output isn't correct |
14 |
Incorrect |
410 ms |
118108 KB |
Output isn't correct |
15 |
Incorrect |
555 ms |
118008 KB |
Output isn't correct |
16 |
Incorrect |
612 ms |
117880 KB |
Output isn't correct |
17 |
Incorrect |
589 ms |
118224 KB |
Output isn't correct |
18 |
Incorrect |
772 ms |
118248 KB |
Output isn't correct |
19 |
Incorrect |
242 ms |
117824 KB |
Output isn't correct |
20 |
Incorrect |
702 ms |
118392 KB |
Output isn't correct |
21 |
Incorrect |
435 ms |
118136 KB |
Output isn't correct |
22 |
Incorrect |
797 ms |
118644 KB |
Output isn't correct |
23 |
Incorrect |
404 ms |
118356 KB |
Output isn't correct |
24 |
Incorrect |
309 ms |
118136 KB |
Output isn't correct |
25 |
Incorrect |
494 ms |
118108 KB |
Output isn't correct |
26 |
Incorrect |
458 ms |
118120 KB |
Output isn't correct |
27 |
Incorrect |
763 ms |
118552 KB |
Output isn't correct |
28 |
Incorrect |
283 ms |
118136 KB |
Output isn't correct |
29 |
Incorrect |
680 ms |
118616 KB |
Output isn't correct |
30 |
Incorrect |
630 ms |
118688 KB |
Output isn't correct |
31 |
Incorrect |
354 ms |
118008 KB |
Output isn't correct |
32 |
Incorrect |
392 ms |
118036 KB |
Output isn't correct |
33 |
Incorrect |
226 ms |
118136 KB |
Output isn't correct |
34 |
Incorrect |
535 ms |
118388 KB |
Output isn't correct |
35 |
Incorrect |
305 ms |
118140 KB |
Output isn't correct |
36 |
Incorrect |
695 ms |
118516 KB |
Output isn't correct |
37 |
Incorrect |
318 ms |
118644 KB |
Output isn't correct |
38 |
Incorrect |
569 ms |
118136 KB |
Output isn't correct |
39 |
Incorrect |
305 ms |
118136 KB |
Output isn't correct |
40 |
Incorrect |
499 ms |
118244 KB |
Output isn't correct |
41 |
Correct |
437 ms |
118364 KB |
Output is correct |
42 |
Incorrect |
614 ms |
118108 KB |
Output isn't correct |