#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("03")
#define int long long
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define FOR(i, n) for (int i = 0; i < n; i++)
#define NYOOM ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
const int INF = 1e9 + 7;
const ll LLINF = 1ll<<60;
const int maxn = 1e8 + 10;
signed main(){
int m, q; cin >> m >> q;
int p[m]; FOR(i, m) cin >> p[i];
vector<int> x; int mx = LLINF;
int last = 1; x.PB(1);
while (last < maxn){
int next = -1;
FOR(i, m){
int val = ((last - 1) / p[i] + 1) * p[i];
next = max(next, val);
}
x.PB(next);
if (next == last){
mx = next;
break;
}
last = next;
}
while (q--){
int n; cin >> n;
if (n >= mx){
cout << "oo" << endl;
continue;
}
int idx = upper_bound(ALL(x), n) - x.begin();
cout << idx << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
79 ms |
2360 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
31 ms |
716 KB |
Output is correct |
5 |
Correct |
151 ms |
16832 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
428 KB |
Output is correct |
8 |
Correct |
3 ms |
848 KB |
Output is correct |
9 |
Correct |
280 ms |
33248 KB |
Output is correct |
10 |
Correct |
153 ms |
8640 KB |
Output is correct |
11 |
Correct |
153 ms |
8564 KB |
Output is correct |
12 |
Correct |
27 ms |
928 KB |
Output is correct |
13 |
Correct |
87 ms |
412 KB |
Output is correct |
14 |
Correct |
104 ms |
524 KB |
Output is correct |
15 |
Correct |
64 ms |
2508 KB |
Output is correct |
16 |
Correct |
75 ms |
2372 KB |
Output is correct |
17 |
Correct |
99 ms |
2496 KB |
Output is correct |
18 |
Correct |
34 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
468 KB |
Output is correct |
2 |
Correct |
35 ms |
1696 KB |
Output is correct |
3 |
Correct |
53 ms |
1296 KB |
Output is correct |
4 |
Correct |
24 ms |
340 KB |
Output is correct |
5 |
Correct |
42 ms |
980 KB |
Output is correct |
6 |
Correct |
12 ms |
324 KB |
Output is correct |
7 |
Correct |
13 ms |
468 KB |
Output is correct |
8 |
Correct |
24 ms |
340 KB |
Output is correct |
9 |
Correct |
54 ms |
1328 KB |
Output is correct |
10 |
Correct |
54 ms |
1296 KB |
Output is correct |
11 |
Correct |
55 ms |
852 KB |
Output is correct |
12 |
Correct |
29 ms |
328 KB |
Output is correct |
13 |
Correct |
5 ms |
308 KB |
Output is correct |
14 |
Correct |
21 ms |
344 KB |
Output is correct |
15 |
Correct |
44 ms |
880 KB |
Output is correct |
16 |
Correct |
34 ms |
1692 KB |
Output is correct |
17 |
Correct |
63 ms |
344 KB |
Output is correct |
18 |
Correct |
58 ms |
1780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
1304 KB |
Output is correct |
2 |
Correct |
97 ms |
1180 KB |
Output is correct |
3 |
Correct |
142 ms |
1568 KB |
Output is correct |
4 |
Correct |
190 ms |
1220 KB |
Output is correct |
5 |
Correct |
195 ms |
2712 KB |
Output is correct |
6 |
Correct |
197 ms |
1360 KB |
Output is correct |
7 |
Correct |
180 ms |
2332 KB |
Output is correct |
8 |
Correct |
107 ms |
1328 KB |
Output is correct |
9 |
Correct |
112 ms |
1312 KB |
Output is correct |
10 |
Correct |
63 ms |
444 KB |
Output is correct |
11 |
Correct |
72 ms |
460 KB |
Output is correct |
12 |
Correct |
78 ms |
580 KB |
Output is correct |
13 |
Correct |
186 ms |
1656 KB |
Output is correct |
14 |
Correct |
377 ms |
8564 KB |
Output is correct |
15 |
Correct |
92 ms |
632 KB |
Output is correct |
16 |
Correct |
98 ms |
580 KB |
Output is correct |
17 |
Correct |
75 ms |
1020 KB |
Output is correct |
18 |
Correct |
103 ms |
1228 KB |
Output is correct |
19 |
Correct |
40 ms |
548 KB |
Output is correct |
20 |
Correct |
141 ms |
1548 KB |
Output is correct |
21 |
Correct |
261 ms |
2688 KB |
Output is correct |
22 |
Correct |
231 ms |
2708 KB |
Output is correct |
23 |
Correct |
183 ms |
1704 KB |
Output is correct |
24 |
Correct |
161 ms |
1208 KB |
Output is correct |
25 |
Correct |
215 ms |
1324 KB |
Output is correct |
26 |
Correct |
163 ms |
1220 KB |
Output is correct |
27 |
Correct |
161 ms |
2196 KB |
Output is correct |
28 |
Correct |
186 ms |
1348 KB |
Output is correct |
29 |
Correct |
231 ms |
2720 KB |
Output is correct |
30 |
Correct |
217 ms |
2368 KB |
Output is correct |
31 |
Correct |
154 ms |
1224 KB |
Output is correct |
32 |
Correct |
201 ms |
1260 KB |
Output is correct |
33 |
Correct |
145 ms |
1232 KB |
Output is correct |
34 |
Correct |
140 ms |
2256 KB |
Output is correct |
35 |
Correct |
182 ms |
1392 KB |
Output is correct |
36 |
Correct |
212 ms |
2576 KB |
Output is correct |
37 |
Correct |
208 ms |
2740 KB |
Output is correct |
38 |
Correct |
194 ms |
1356 KB |
Output is correct |
39 |
Correct |
178 ms |
1372 KB |
Output is correct |
40 |
Correct |
176 ms |
1360 KB |
Output is correct |
41 |
Correct |
148 ms |
2456 KB |
Output is correct |
42 |
Correct |
218 ms |
1520 KB |
Output is correct |