#include <bits/stdc++.h>
const int32_t MAX_N = 1e7 + 1e6;
int32_t dp[MAX_N + 5];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int32_t m, q;
std::cin >> m >> q;
int64_t lcm = 1;
for(int32_t i = 0; i < m; i++) {
int32_t p;
std::cin >> p;
for(int32_t j = p - 1; j <= MAX_N; j += p) {
dp[j] = p - 1;
}
if(lcm < MAX_N) {
lcm *= (int64_t) p;
}
}
for(int32_t i = MAX_N - 1; i >= 1; i--) {
dp[i] = std::max(dp[i], dp[i + 1] - 1);
}
dp[0] = 0;
for(int32_t i = 1; i <= MAX_N; i++) {
dp[i] = dp[i - dp[i]] + 1;
}
for(int32_t i = 0; i < q; i++) {
int32_t n;
std::cin >> n;
if(n >= lcm) {
std::cout << "oo" << '\n';
}
else {
std::cout << dp[n] << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
43384 KB |
Output is correct |
2 |
Correct |
154 ms |
43684 KB |
Output is correct |
3 |
Correct |
112 ms |
43684 KB |
Output is correct |
4 |
Correct |
104 ms |
43684 KB |
Output is correct |
5 |
Correct |
141 ms |
43684 KB |
Output is correct |
6 |
Correct |
107 ms |
43684 KB |
Output is correct |
7 |
Correct |
124 ms |
43684 KB |
Output is correct |
8 |
Correct |
119 ms |
43684 KB |
Output is correct |
9 |
Correct |
144 ms |
43756 KB |
Output is correct |
10 |
Correct |
182 ms |
43756 KB |
Output is correct |
11 |
Correct |
172 ms |
43756 KB |
Output is correct |
12 |
Correct |
110 ms |
43756 KB |
Output is correct |
13 |
Correct |
345 ms |
43756 KB |
Output is correct |
14 |
Correct |
370 ms |
43756 KB |
Output is correct |
15 |
Correct |
173 ms |
43772 KB |
Output is correct |
16 |
Correct |
149 ms |
43772 KB |
Output is correct |
17 |
Correct |
153 ms |
43772 KB |
Output is correct |
18 |
Correct |
120 ms |
43832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
43832 KB |
Output is correct |
2 |
Correct |
171 ms |
43832 KB |
Output is correct |
3 |
Correct |
498 ms |
43832 KB |
Output is correct |
4 |
Correct |
200 ms |
43832 KB |
Output is correct |
5 |
Correct |
288 ms |
43916 KB |
Output is correct |
6 |
Correct |
133 ms |
43916 KB |
Output is correct |
7 |
Correct |
133 ms |
43916 KB |
Output is correct |
8 |
Correct |
184 ms |
43916 KB |
Output is correct |
9 |
Correct |
388 ms |
43916 KB |
Output is correct |
10 |
Correct |
474 ms |
43916 KB |
Output is correct |
11 |
Correct |
418 ms |
43916 KB |
Output is correct |
12 |
Correct |
224 ms |
43916 KB |
Output is correct |
13 |
Correct |
97 ms |
43916 KB |
Output is correct |
14 |
Correct |
196 ms |
43916 KB |
Output is correct |
15 |
Correct |
350 ms |
43916 KB |
Output is correct |
16 |
Correct |
162 ms |
43916 KB |
Output is correct |
17 |
Correct |
361 ms |
43916 KB |
Output is correct |
18 |
Correct |
358 ms |
43916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
353 ms |
43916 KB |
Output is correct |
2 |
Correct |
455 ms |
43916 KB |
Output is correct |
3 |
Correct |
483 ms |
43916 KB |
Output is correct |
4 |
Correct |
274 ms |
43916 KB |
Output is correct |
5 |
Correct |
194 ms |
43916 KB |
Output is correct |
6 |
Correct |
355 ms |
44020 KB |
Output is correct |
7 |
Correct |
376 ms |
44020 KB |
Output is correct |
8 |
Correct |
406 ms |
44020 KB |
Output is correct |
9 |
Correct |
425 ms |
44020 KB |
Output is correct |
10 |
Correct |
321 ms |
44020 KB |
Output is correct |
11 |
Correct |
277 ms |
44020 KB |
Output is correct |
12 |
Correct |
361 ms |
44020 KB |
Output is correct |
13 |
Correct |
425 ms |
44020 KB |
Output is correct |
14 |
Correct |
340 ms |
44272 KB |
Output is correct |
15 |
Correct |
337 ms |
44272 KB |
Output is correct |
16 |
Correct |
390 ms |
44272 KB |
Output is correct |
17 |
Correct |
336 ms |
44272 KB |
Output is correct |
18 |
Correct |
431 ms |
44272 KB |
Output is correct |
19 |
Correct |
183 ms |
44272 KB |
Output is correct |
20 |
Correct |
451 ms |
44272 KB |
Output is correct |
21 |
Correct |
247 ms |
44272 KB |
Output is correct |
22 |
Correct |
485 ms |
44272 KB |
Output is correct |
23 |
Correct |
231 ms |
44272 KB |
Output is correct |
24 |
Correct |
183 ms |
44272 KB |
Output is correct |
25 |
Correct |
336 ms |
44272 KB |
Output is correct |
26 |
Correct |
302 ms |
44272 KB |
Output is correct |
27 |
Correct |
553 ms |
44272 KB |
Output is correct |
28 |
Correct |
150 ms |
44272 KB |
Output is correct |
29 |
Correct |
473 ms |
44272 KB |
Output is correct |
30 |
Correct |
399 ms |
44272 KB |
Output is correct |
31 |
Correct |
183 ms |
44272 KB |
Output is correct |
32 |
Correct |
241 ms |
44272 KB |
Output is correct |
33 |
Correct |
154 ms |
44272 KB |
Output is correct |
34 |
Correct |
377 ms |
44272 KB |
Output is correct |
35 |
Correct |
178 ms |
44272 KB |
Output is correct |
36 |
Correct |
516 ms |
44272 KB |
Output is correct |
37 |
Correct |
230 ms |
44272 KB |
Output is correct |
38 |
Correct |
403 ms |
44272 KB |
Output is correct |
39 |
Correct |
192 ms |
44272 KB |
Output is correct |
40 |
Correct |
311 ms |
44272 KB |
Output is correct |
41 |
Correct |
307 ms |
44272 KB |
Output is correct |
42 |
Correct |
441 ms |
44272 KB |
Output is correct |