#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 = MAXN - 1;
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] = 987654321;
else dp[i] = dp[to[i]] + 1;
FOR(i, 0, q) {
int x;
cin >> x;
if (dp[x] >= 987654321)
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 |
208 ms |
235132 KB |
Output is correct |
2 |
Correct |
243 ms |
235000 KB |
Output is correct |
3 |
Correct |
230 ms |
235300 KB |
Output is correct |
4 |
Correct |
211 ms |
235244 KB |
Output is correct |
5 |
Correct |
226 ms |
235128 KB |
Output is correct |
6 |
Correct |
210 ms |
235128 KB |
Output is correct |
7 |
Correct |
231 ms |
235172 KB |
Output is correct |
8 |
Correct |
242 ms |
235128 KB |
Output is correct |
9 |
Correct |
273 ms |
235220 KB |
Output is correct |
10 |
Correct |
304 ms |
235128 KB |
Output is correct |
11 |
Correct |
284 ms |
235128 KB |
Output is correct |
12 |
Correct |
225 ms |
235188 KB |
Output is correct |
13 |
Correct |
444 ms |
235172 KB |
Output is correct |
14 |
Correct |
451 ms |
235248 KB |
Output is correct |
15 |
Correct |
259 ms |
235128 KB |
Output is correct |
16 |
Correct |
288 ms |
235256 KB |
Output is correct |
17 |
Correct |
288 ms |
235356 KB |
Output is correct |
18 |
Correct |
240 ms |
235288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
235396 KB |
Output is correct |
2 |
Correct |
246 ms |
236420 KB |
Output is correct |
3 |
Correct |
521 ms |
236252 KB |
Output is correct |
4 |
Correct |
271 ms |
235356 KB |
Output is correct |
5 |
Correct |
375 ms |
235976 KB |
Output is correct |
6 |
Correct |
239 ms |
235244 KB |
Output is correct |
7 |
Correct |
229 ms |
235512 KB |
Output is correct |
8 |
Correct |
260 ms |
235256 KB |
Output is correct |
9 |
Correct |
415 ms |
236228 KB |
Output is correct |
10 |
Correct |
524 ms |
236244 KB |
Output is correct |
11 |
Incorrect |
503 ms |
235896 KB |
Output isn't correct |
12 |
Correct |
322 ms |
235128 KB |
Output is correct |
13 |
Correct |
220 ms |
235256 KB |
Output is correct |
14 |
Correct |
263 ms |
235256 KB |
Output is correct |
15 |
Correct |
432 ms |
235932 KB |
Output is correct |
16 |
Correct |
275 ms |
236408 KB |
Output is correct |
17 |
Correct |
447 ms |
235308 KB |
Output is correct |
18 |
Correct |
463 ms |
236492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
542 ms |
236212 KB |
Output is correct |
2 |
Correct |
535 ms |
236172 KB |
Output is correct |
3 |
Correct |
528 ms |
236280 KB |
Output is correct |
4 |
Incorrect |
362 ms |
236108 KB |
Output isn't correct |
5 |
Incorrect |
311 ms |
236768 KB |
Output isn't correct |
6 |
Correct |
460 ms |
236032 KB |
Output is correct |
7 |
Correct |
436 ms |
236704 KB |
Output is correct |
8 |
Correct |
489 ms |
236076 KB |
Output is correct |
9 |
Correct |
459 ms |
236260 KB |
Output is correct |
10 |
Correct |
378 ms |
235380 KB |
Output is correct |
11 |
Incorrect |
380 ms |
235596 KB |
Output isn't correct |
12 |
Correct |
416 ms |
235512 KB |
Output is correct |
13 |
Correct |
547 ms |
236280 KB |
Output is correct |
14 |
Correct |
385 ms |
236372 KB |
Output is correct |
15 |
Incorrect |
461 ms |
235612 KB |
Output isn't correct |
16 |
Correct |
483 ms |
235512 KB |
Output is correct |
17 |
Correct |
420 ms |
236028 KB |
Output is correct |
18 |
Correct |
584 ms |
236152 KB |
Output is correct |
19 |
Incorrect |
242 ms |
235580 KB |
Output isn't correct |
20 |
Correct |
565 ms |
236268 KB |
Output is correct |
21 |
Incorrect |
383 ms |
236380 KB |
Output isn't correct |
22 |
Correct |
589 ms |
236920 KB |
Output is correct |
23 |
Correct |
293 ms |
236152 KB |
Output is correct |
24 |
Correct |
256 ms |
236056 KB |
Output is correct |
25 |
Incorrect |
389 ms |
236208 KB |
Output isn't correct |
26 |
Incorrect |
401 ms |
235996 KB |
Output isn't correct |
27 |
Correct |
611 ms |
236536 KB |
Output is correct |
28 |
Incorrect |
258 ms |
236096 KB |
Output isn't correct |
29 |
Correct |
515 ms |
236828 KB |
Output is correct |
30 |
Correct |
462 ms |
236436 KB |
Output is correct |
31 |
Correct |
285 ms |
235996 KB |
Output is correct |
32 |
Incorrect |
304 ms |
236024 KB |
Output isn't correct |
33 |
Incorrect |
245 ms |
236152 KB |
Output isn't correct |
34 |
Correct |
499 ms |
236536 KB |
Output is correct |
35 |
Incorrect |
307 ms |
236024 KB |
Output isn't correct |
36 |
Correct |
586 ms |
236540 KB |
Output is correct |
37 |
Incorrect |
294 ms |
236684 KB |
Output isn't correct |
38 |
Correct |
477 ms |
236124 KB |
Output is correct |
39 |
Incorrect |
269 ms |
236024 KB |
Output isn't correct |
40 |
Correct |
448 ms |
236028 KB |
Output is correct |
41 |
Correct |
361 ms |
236520 KB |
Output is correct |
42 |
Incorrect |
493 ms |
236152 KB |
Output isn't correct |