#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] = -1;
else dp[i] = dp[to[i]] + 1;
FOR(i, 0, q) {
int x;
cin >> x;
if (dp[x] == -1)
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 |
Incorrect |
219 ms |
235276 KB |
Output isn't correct |
2 |
Correct |
251 ms |
235132 KB |
Output is correct |
3 |
Correct |
237 ms |
235292 KB |
Output is correct |
4 |
Correct |
218 ms |
235256 KB |
Output is correct |
5 |
Correct |
245 ms |
235124 KB |
Output is correct |
6 |
Incorrect |
218 ms |
235316 KB |
Output isn't correct |
7 |
Correct |
235 ms |
235120 KB |
Output is correct |
8 |
Correct |
248 ms |
235128 KB |
Output is correct |
9 |
Correct |
276 ms |
235256 KB |
Output is correct |
10 |
Correct |
319 ms |
235216 KB |
Output is correct |
11 |
Correct |
295 ms |
235172 KB |
Output is correct |
12 |
Correct |
218 ms |
235104 KB |
Output is correct |
13 |
Correct |
449 ms |
235132 KB |
Output is correct |
14 |
Correct |
460 ms |
235244 KB |
Output is correct |
15 |
Correct |
267 ms |
235256 KB |
Output is correct |
16 |
Correct |
251 ms |
235208 KB |
Output is correct |
17 |
Correct |
275 ms |
235340 KB |
Output is correct |
18 |
Correct |
220 ms |
235308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
237 ms |
235332 KB |
Output is correct |
2 |
Correct |
252 ms |
236536 KB |
Output is correct |
3 |
Correct |
543 ms |
236176 KB |
Output is correct |
4 |
Correct |
274 ms |
235256 KB |
Output is correct |
5 |
Correct |
392 ms |
236024 KB |
Output is correct |
6 |
Correct |
244 ms |
235128 KB |
Output is correct |
7 |
Correct |
238 ms |
235384 KB |
Output is correct |
8 |
Correct |
267 ms |
235116 KB |
Output is correct |
9 |
Correct |
436 ms |
236380 KB |
Output is correct |
10 |
Correct |
545 ms |
236144 KB |
Output is correct |
11 |
Incorrect |
538 ms |
235896 KB |
Output isn't correct |
12 |
Correct |
333 ms |
235132 KB |
Output is correct |
13 |
Correct |
227 ms |
235256 KB |
Output is correct |
14 |
Correct |
272 ms |
235408 KB |
Output is correct |
15 |
Correct |
517 ms |
235896 KB |
Output is correct |
16 |
Correct |
257 ms |
236664 KB |
Output is correct |
17 |
Correct |
463 ms |
235384 KB |
Output is correct |
18 |
Incorrect |
448 ms |
236664 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
464 ms |
236324 KB |
Output is correct |
2 |
Correct |
560 ms |
236124 KB |
Output is correct |
3 |
Correct |
554 ms |
236540 KB |
Output is correct |
4 |
Incorrect |
402 ms |
236176 KB |
Output isn't correct |
5 |
Incorrect |
341 ms |
237564 KB |
Output isn't correct |
6 |
Correct |
463 ms |
236324 KB |
Output is correct |
7 |
Correct |
433 ms |
237220 KB |
Output is correct |
8 |
Correct |
471 ms |
236384 KB |
Output is correct |
9 |
Correct |
469 ms |
236252 KB |
Output is correct |
10 |
Correct |
394 ms |
235412 KB |
Output is correct |
11 |
Incorrect |
330 ms |
235512 KB |
Output isn't correct |
12 |
Correct |
427 ms |
235512 KB |
Output is correct |
13 |
Correct |
527 ms |
236628 KB |
Output is correct |
14 |
Correct |
342 ms |
236536 KB |
Output is correct |
15 |
Incorrect |
452 ms |
235512 KB |
Output isn't correct |
16 |
Correct |
501 ms |
235512 KB |
Output is correct |
17 |
Correct |
437 ms |
235976 KB |
Output is correct |
18 |
Correct |
545 ms |
236256 KB |
Output is correct |
19 |
Incorrect |
240 ms |
235608 KB |
Output isn't correct |
20 |
Correct |
545 ms |
236488 KB |
Output is correct |
21 |
Incorrect |
389 ms |
236752 KB |
Output isn't correct |
22 |
Correct |
565 ms |
237652 KB |
Output is correct |
23 |
Correct |
300 ms |
236616 KB |
Output is correct |
24 |
Correct |
260 ms |
236340 KB |
Output is correct |
25 |
Incorrect |
396 ms |
236280 KB |
Output isn't correct |
26 |
Incorrect |
365 ms |
236152 KB |
Output isn't correct |
27 |
Correct |
592 ms |
237148 KB |
Output is correct |
28 |
Incorrect |
265 ms |
236264 KB |
Output isn't correct |
29 |
Correct |
519 ms |
237560 KB |
Output is correct |
30 |
Correct |
508 ms |
237176 KB |
Output is correct |
31 |
Correct |
286 ms |
236180 KB |
Output is correct |
32 |
Incorrect |
319 ms |
236280 KB |
Output isn't correct |
33 |
Incorrect |
240 ms |
236152 KB |
Output isn't correct |
34 |
Correct |
401 ms |
237188 KB |
Output is correct |
35 |
Incorrect |
268 ms |
236408 KB |
Output isn't correct |
36 |
Correct |
539 ms |
237532 KB |
Output is correct |
37 |
Incorrect |
298 ms |
237564 KB |
Output isn't correct |
38 |
Correct |
518 ms |
236380 KB |
Output is correct |
39 |
Incorrect |
272 ms |
236280 KB |
Output isn't correct |
40 |
Correct |
408 ms |
236272 KB |
Output is correct |
41 |
Correct |
366 ms |
237356 KB |
Output is correct |
42 |
Incorrect |
513 ms |
236536 KB |
Output isn't correct |