#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; 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;
}
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")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
218 ms |
235228 KB |
Output is correct |
2 |
Correct |
250 ms |
235128 KB |
Output is correct |
3 |
Correct |
238 ms |
235256 KB |
Output is correct |
4 |
Correct |
259 ms |
235356 KB |
Output is correct |
5 |
Correct |
248 ms |
235216 KB |
Output is correct |
6 |
Correct |
227 ms |
235220 KB |
Output is correct |
7 |
Correct |
237 ms |
235252 KB |
Output is correct |
8 |
Correct |
248 ms |
235128 KB |
Output is correct |
9 |
Correct |
286 ms |
235200 KB |
Output is correct |
10 |
Correct |
315 ms |
235276 KB |
Output is correct |
11 |
Correct |
290 ms |
235128 KB |
Output is correct |
12 |
Correct |
215 ms |
235128 KB |
Output is correct |
13 |
Correct |
447 ms |
235228 KB |
Output is correct |
14 |
Correct |
451 ms |
235232 KB |
Output is correct |
15 |
Correct |
283 ms |
235184 KB |
Output is correct |
16 |
Correct |
302 ms |
235096 KB |
Output is correct |
17 |
Correct |
317 ms |
235220 KB |
Output is correct |
18 |
Correct |
221 ms |
235128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
235284 KB |
Output is correct |
2 |
Correct |
257 ms |
235992 KB |
Output is correct |
3 |
Correct |
549 ms |
235764 KB |
Output is correct |
4 |
Correct |
294 ms |
235256 KB |
Output is correct |
5 |
Correct |
449 ms |
235640 KB |
Output is correct |
6 |
Correct |
245 ms |
235128 KB |
Output is correct |
7 |
Correct |
263 ms |
235308 KB |
Output is correct |
8 |
Correct |
272 ms |
235256 KB |
Output is correct |
9 |
Correct |
436 ms |
235768 KB |
Output is correct |
10 |
Correct |
528 ms |
235868 KB |
Output is correct |
11 |
Incorrect |
522 ms |
235512 KB |
Output isn't correct |
12 |
Correct |
329 ms |
235260 KB |
Output is correct |
13 |
Correct |
260 ms |
235384 KB |
Output is correct |
14 |
Correct |
331 ms |
235248 KB |
Output is correct |
15 |
Correct |
498 ms |
235672 KB |
Output is correct |
16 |
Correct |
255 ms |
235896 KB |
Output is correct |
17 |
Correct |
480 ms |
235380 KB |
Output is correct |
18 |
Incorrect |
454 ms |
236000 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
467 ms |
235768 KB |
Output is correct |
2 |
Correct |
543 ms |
235664 KB |
Output is correct |
3 |
Correct |
550 ms |
235868 KB |
Output is correct |
4 |
Incorrect |
414 ms |
235472 KB |
Output isn't correct |
5 |
Incorrect |
293 ms |
236184 KB |
Output isn't correct |
6 |
Correct |
464 ms |
235512 KB |
Output is correct |
7 |
Correct |
418 ms |
236024 KB |
Output is correct |
8 |
Correct |
482 ms |
235652 KB |
Output is correct |
9 |
Correct |
558 ms |
235664 KB |
Output is correct |
10 |
Correct |
388 ms |
235332 KB |
Output is correct |
11 |
Incorrect |
331 ms |
235384 KB |
Output isn't correct |
12 |
Correct |
490 ms |
235256 KB |
Output is correct |
13 |
Correct |
517 ms |
235640 KB |
Output is correct |
14 |
Correct |
349 ms |
236004 KB |
Output is correct |
15 |
Incorrect |
477 ms |
235384 KB |
Output isn't correct |
16 |
Correct |
501 ms |
235416 KB |
Output is correct |
17 |
Correct |
431 ms |
235696 KB |
Output is correct |
18 |
Correct |
549 ms |
235644 KB |
Output is correct |
19 |
Incorrect |
235 ms |
235256 KB |
Output isn't correct |
20 |
Correct |
600 ms |
235760 KB |
Output is correct |
21 |
Incorrect |
390 ms |
235888 KB |
Output isn't correct |
22 |
Correct |
555 ms |
236156 KB |
Output is correct |
23 |
Correct |
294 ms |
235640 KB |
Output is correct |
24 |
Correct |
257 ms |
235384 KB |
Output is correct |
25 |
Incorrect |
406 ms |
235500 KB |
Output isn't correct |
26 |
Incorrect |
372 ms |
235440 KB |
Output isn't correct |
27 |
Correct |
614 ms |
236108 KB |
Output is correct |
28 |
Incorrect |
262 ms |
235512 KB |
Output isn't correct |
29 |
Correct |
516 ms |
236280 KB |
Output is correct |
30 |
Correct |
538 ms |
236016 KB |
Output is correct |
31 |
Correct |
332 ms |
235512 KB |
Output is correct |
32 |
Incorrect |
309 ms |
235512 KB |
Output isn't correct |
33 |
Incorrect |
241 ms |
235512 KB |
Output isn't correct |
34 |
Correct |
405 ms |
236152 KB |
Output is correct |
35 |
Incorrect |
268 ms |
235640 KB |
Output isn't correct |
36 |
Correct |
607 ms |
236152 KB |
Output is correct |
37 |
Incorrect |
307 ms |
236208 KB |
Output isn't correct |
38 |
Correct |
467 ms |
235632 KB |
Output is correct |
39 |
Incorrect |
275 ms |
235460 KB |
Output isn't correct |
40 |
Correct |
452 ms |
235456 KB |
Output is correct |
41 |
Correct |
363 ms |
235996 KB |
Output is correct |
42 |
Incorrect |
507 ms |
235656 KB |
Output isn't correct |