#include <bits/stdc++.h>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MAXN 10000001
typedef long long ll;
using namespace std;
ll dp[MAXN], p[100001], max_divide[MAXN], to[MAXN];
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 + 1; j += p[i]) max_divide[j] = p[i];
ll mn = INT_MAX;
for (int i = MAXN - 1; i > 0; i--) {
mn = min(mn, i + 1 - max_divide[i + 1]);
to[i] = mn;
}
dp[0] = 0;
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
brunhilda.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
#pragma GCC Optimize("O3")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
235128 KB |
Output is correct |
2 |
Correct |
256 ms |
235256 KB |
Output is correct |
3 |
Correct |
237 ms |
235212 KB |
Output is correct |
4 |
Correct |
221 ms |
235216 KB |
Output is correct |
5 |
Correct |
257 ms |
235180 KB |
Output is correct |
6 |
Correct |
236 ms |
235228 KB |
Output is correct |
7 |
Correct |
236 ms |
235168 KB |
Output is correct |
8 |
Correct |
248 ms |
235168 KB |
Output is correct |
9 |
Correct |
283 ms |
235228 KB |
Output is correct |
10 |
Correct |
311 ms |
235208 KB |
Output is correct |
11 |
Correct |
296 ms |
235224 KB |
Output is correct |
12 |
Correct |
214 ms |
235212 KB |
Output is correct |
13 |
Correct |
458 ms |
235220 KB |
Output is correct |
14 |
Correct |
468 ms |
235244 KB |
Output is correct |
15 |
Correct |
274 ms |
235168 KB |
Output is correct |
16 |
Correct |
252 ms |
235228 KB |
Output is correct |
17 |
Correct |
261 ms |
235184 KB |
Output is correct |
18 |
Correct |
222 ms |
235268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
242 ms |
235364 KB |
Output is correct |
2 |
Correct |
255 ms |
235988 KB |
Output is correct |
3 |
Correct |
551 ms |
235776 KB |
Output is correct |
4 |
Correct |
276 ms |
235252 KB |
Output is correct |
5 |
Correct |
391 ms |
235680 KB |
Output is correct |
6 |
Correct |
243 ms |
235196 KB |
Output is correct |
7 |
Correct |
235 ms |
235392 KB |
Output is correct |
8 |
Correct |
270 ms |
235240 KB |
Output is correct |
9 |
Correct |
439 ms |
235900 KB |
Output is correct |
10 |
Correct |
576 ms |
235976 KB |
Output is correct |
11 |
Incorrect |
529 ms |
235728 KB |
Output isn't correct |
12 |
Correct |
339 ms |
235184 KB |
Output is correct |
13 |
Correct |
230 ms |
235256 KB |
Output is correct |
14 |
Correct |
275 ms |
235236 KB |
Output is correct |
15 |
Correct |
454 ms |
235704 KB |
Output is correct |
16 |
Correct |
256 ms |
236136 KB |
Output is correct |
17 |
Correct |
487 ms |
235248 KB |
Output is correct |
18 |
Correct |
450 ms |
236136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
471 ms |
235780 KB |
Output is correct |
2 |
Correct |
545 ms |
235876 KB |
Output is correct |
3 |
Correct |
549 ms |
235944 KB |
Output is correct |
4 |
Incorrect |
372 ms |
235616 KB |
Output isn't correct |
5 |
Incorrect |
312 ms |
236476 KB |
Output isn't correct |
6 |
Correct |
470 ms |
235724 KB |
Output is correct |
7 |
Correct |
404 ms |
236232 KB |
Output is correct |
8 |
Correct |
470 ms |
235836 KB |
Output is correct |
9 |
Correct |
516 ms |
235940 KB |
Output is correct |
10 |
Correct |
389 ms |
235376 KB |
Output is correct |
11 |
Incorrect |
363 ms |
235532 KB |
Output isn't correct |
12 |
Correct |
433 ms |
235512 KB |
Output is correct |
13 |
Correct |
528 ms |
235916 KB |
Output is correct |
14 |
Correct |
349 ms |
236012 KB |
Output is correct |
15 |
Incorrect |
466 ms |
235592 KB |
Output isn't correct |
16 |
Correct |
501 ms |
235572 KB |
Output is correct |
17 |
Correct |
447 ms |
235896 KB |
Output is correct |
18 |
Correct |
557 ms |
235896 KB |
Output is correct |
19 |
Incorrect |
244 ms |
235384 KB |
Output isn't correct |
20 |
Correct |
558 ms |
235944 KB |
Output is correct |
21 |
Incorrect |
409 ms |
236024 KB |
Output isn't correct |
22 |
Correct |
571 ms |
236536 KB |
Output is correct |
23 |
Correct |
317 ms |
235872 KB |
Output is correct |
24 |
Correct |
263 ms |
235720 KB |
Output is correct |
25 |
Incorrect |
403 ms |
235760 KB |
Output isn't correct |
26 |
Incorrect |
373 ms |
235768 KB |
Output isn't correct |
27 |
Correct |
612 ms |
236252 KB |
Output is correct |
28 |
Incorrect |
262 ms |
235856 KB |
Output isn't correct |
29 |
Correct |
527 ms |
236508 KB |
Output is correct |
30 |
Correct |
486 ms |
236136 KB |
Output is correct |
31 |
Correct |
293 ms |
235660 KB |
Output is correct |
32 |
Incorrect |
314 ms |
235828 KB |
Output isn't correct |
33 |
Incorrect |
247 ms |
235600 KB |
Output isn't correct |
34 |
Correct |
408 ms |
236312 KB |
Output is correct |
35 |
Incorrect |
312 ms |
235828 KB |
Output isn't correct |
36 |
Correct |
617 ms |
236360 KB |
Output is correct |
37 |
Incorrect |
325 ms |
236472 KB |
Output isn't correct |
38 |
Correct |
493 ms |
235800 KB |
Output is correct |
39 |
Incorrect |
283 ms |
235640 KB |
Output isn't correct |
40 |
Correct |
423 ms |
235900 KB |
Output is correct |
41 |
Correct |
374 ms |
236236 KB |
Output is correct |
42 |
Incorrect |
514 ms |
235896 KB |
Output isn't correct |