#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
int n, q;
vector<int> p;
vector<int> v;
int prime[N];
int prv[N];
int dp[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
p.resize(n);
for(int i = 0; i < n; i++) cin >> p[i];
for(int i : p) {
for(int j = i; j < N; j += i) {
v.push_back(j);
prime[j] = max(prime[j], i);
}
}
v.push_back(0);
prime[0] = p.back();
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
int j = 0;
for(int i = 1; i < N; i++) {
while(v[j] + prime[v[j]] <= i) j++;
prv[i] = v[j];
}
for(int i = 1; i < N; i++) {
if(prv[i] == i) dp[i] = -1;
else dp[i] = dp[prv[i]] + 1;
}
while(q--) {
int x;
cin >> x;
if(dp[x] == -1) cout << "oo\n";
else cout << dp[x] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
220 ms |
124944 KB |
Output isn't correct |
2 |
Correct |
977 ms |
158104 KB |
Output is correct |
3 |
Execution timed out |
1008 ms |
148060 KB |
Time limit exceeded |
4 |
Correct |
124 ms |
120856 KB |
Output is correct |
5 |
Correct |
279 ms |
129484 KB |
Output is correct |
6 |
Incorrect |
236 ms |
124840 KB |
Output isn't correct |
7 |
Execution timed out |
1006 ms |
148136 KB |
Time limit exceeded |
8 |
Execution timed out |
1034 ms |
161360 KB |
Time limit exceeded |
9 |
Execution timed out |
1081 ms |
105164 KB |
Time limit exceeded |
10 |
Execution timed out |
1072 ms |
105184 KB |
Time limit exceeded |
11 |
Correct |
835 ms |
160468 KB |
Output is correct |
12 |
Correct |
112 ms |
119944 KB |
Output is correct |
13 |
Execution timed out |
1090 ms |
171040 KB |
Time limit exceeded |
14 |
Execution timed out |
1075 ms |
170872 KB |
Time limit exceeded |
15 |
Execution timed out |
1085 ms |
105204 KB |
Time limit exceeded |
16 |
Correct |
938 ms |
158092 KB |
Output is correct |
17 |
Correct |
291 ms |
129688 KB |
Output is correct |
18 |
Correct |
127 ms |
120788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
124676 KB |
Output is correct |
2 |
Correct |
278 ms |
127520 KB |
Output is correct |
3 |
Execution timed out |
1082 ms |
171124 KB |
Time limit exceeded |
4 |
Correct |
515 ms |
137112 KB |
Output is correct |
5 |
Execution timed out |
1070 ms |
105448 KB |
Time limit exceeded |
6 |
Execution timed out |
1087 ms |
67616 KB |
Time limit exceeded |
7 |
Correct |
249 ms |
124628 KB |
Output is correct |
8 |
Correct |
426 ms |
134936 KB |
Output is correct |
9 |
Execution timed out |
1049 ms |
105544 KB |
Time limit exceeded |
10 |
Execution timed out |
1078 ms |
171188 KB |
Time limit exceeded |
11 |
Execution timed out |
1087 ms |
171032 KB |
Time limit exceeded |
12 |
Execution timed out |
1055 ms |
105368 KB |
Time limit exceeded |
13 |
Correct |
340 ms |
128352 KB |
Output is correct |
14 |
Correct |
574 ms |
137080 KB |
Output is correct |
15 |
Execution timed out |
1083 ms |
171088 KB |
Time limit exceeded |
16 |
Correct |
288 ms |
127620 KB |
Output is correct |
17 |
Execution timed out |
1096 ms |
171068 KB |
Time limit exceeded |
18 |
Execution timed out |
1075 ms |
171340 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
171312 KB |
Time limit exceeded |
2 |
Execution timed out |
1076 ms |
171064 KB |
Time limit exceeded |
3 |
Execution timed out |
1078 ms |
171068 KB |
Time limit exceeded |
4 |
Execution timed out |
1070 ms |
105268 KB |
Time limit exceeded |
5 |
Correct |
335 ms |
128276 KB |
Output is correct |
6 |
Execution timed out |
1082 ms |
170860 KB |
Time limit exceeded |
7 |
Execution timed out |
1041 ms |
157608 KB |
Time limit exceeded |
8 |
Execution timed out |
1088 ms |
171068 KB |
Time limit exceeded |
9 |
Execution timed out |
1082 ms |
171228 KB |
Time limit exceeded |
10 |
Execution timed out |
1091 ms |
122616 KB |
Time limit exceeded |
11 |
Correct |
860 ms |
151360 KB |
Output is correct |
12 |
Execution timed out |
1088 ms |
170924 KB |
Time limit exceeded |
13 |
Execution timed out |
1088 ms |
170948 KB |
Time limit exceeded |
14 |
Execution timed out |
1080 ms |
170904 KB |
Time limit exceeded |
15 |
Execution timed out |
1086 ms |
170944 KB |
Time limit exceeded |
16 |
Execution timed out |
1082 ms |
170936 KB |
Time limit exceeded |
17 |
Execution timed out |
1089 ms |
105340 KB |
Time limit exceeded |
18 |
Execution timed out |
1080 ms |
171172 KB |
Time limit exceeded |
19 |
Correct |
822 ms |
136288 KB |
Output is correct |
20 |
Execution timed out |
1089 ms |
171068 KB |
Time limit exceeded |
21 |
Execution timed out |
1082 ms |
170896 KB |
Time limit exceeded |
22 |
Execution timed out |
1086 ms |
171232 KB |
Time limit exceeded |
23 |
Correct |
373 ms |
129800 KB |
Output is correct |
24 |
Correct |
263 ms |
126536 KB |
Output is correct |
25 |
Execution timed out |
1095 ms |
105268 KB |
Time limit exceeded |
26 |
Execution timed out |
1078 ms |
105216 KB |
Time limit exceeded |
27 |
Execution timed out |
1084 ms |
171200 KB |
Time limit exceeded |
28 |
Correct |
475 ms |
134816 KB |
Output is correct |
29 |
Execution timed out |
1068 ms |
105540 KB |
Time limit exceeded |
30 |
Execution timed out |
1084 ms |
105464 KB |
Time limit exceeded |
31 |
Correct |
484 ms |
136604 KB |
Output is correct |
32 |
Correct |
652 ms |
142576 KB |
Output is correct |
33 |
Correct |
203 ms |
123032 KB |
Output is correct |
34 |
Execution timed out |
1044 ms |
157632 KB |
Time limit exceeded |
35 |
Correct |
667 ms |
135932 KB |
Output is correct |
36 |
Execution timed out |
1085 ms |
171260 KB |
Time limit exceeded |
37 |
Correct |
314 ms |
128308 KB |
Output is correct |
38 |
Execution timed out |
1092 ms |
171004 KB |
Time limit exceeded |
39 |
Correct |
313 ms |
128996 KB |
Output is correct |
40 |
Execution timed out |
1077 ms |
105244 KB |
Time limit exceeded |
41 |
Execution timed out |
1088 ms |
105660 KB |
Time limit exceeded |
42 |
Execution timed out |
1086 ms |
170904 KB |
Time limit exceeded |