#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define foxr1(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
int n, q, x, t, l2, k, lo=(1 << 30), dp[10000005], f[10000005];
vector<bool> p=vector<bool>(10000005);
int main(){
scanf("%i%i", &n, &q);
fox(l, n){
scanf("%i", &x);
p[x]=1;
lo=min(lo, 10000000/x*x);
}
for(int l=2; l<=10000000; l++){
if (f[l]!=0) continue;
if (p[l]) k=l; else k=-1;
if (k==-1){
if (l>10000) continue;
l2=l*l;
} else l2=l;
for (; l2<=10000000; l2+=l){
f[l2]=k;
}
}
foxr1(l, 10000000){
t=lo;
lo=min(lo, l-max(0, f[l]));
f[l]=t;
//cout << f[l] << endl;
}
fox1(l, 10000000){
if (f[l]==l) dp[l]=(1 << 30);
dp[l]=dp[f[l]]+1;
}
fox(l, q){
scanf("%i", &x);
if (dp[x]>=(1 << 30)){
printf("oo\n");
}
else {
printf("%i\n", dp[x]);
}
}
return 0;
}
Compilation message
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:29:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &n, &q);
^
brunhilda.cpp:31:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &x);
^
brunhilda.cpp:57:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &x);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
246 ms |
81368 KB |
Output isn't correct |
2 |
Correct |
283 ms |
81368 KB |
Output is correct |
3 |
Incorrect |
239 ms |
81368 KB |
Output isn't correct |
4 |
Correct |
276 ms |
81368 KB |
Output is correct |
5 |
Correct |
273 ms |
81368 KB |
Output is correct |
6 |
Incorrect |
233 ms |
81368 KB |
Output isn't correct |
7 |
Incorrect |
223 ms |
81368 KB |
Output isn't correct |
8 |
Incorrect |
259 ms |
81368 KB |
Output isn't correct |
9 |
Correct |
259 ms |
81368 KB |
Output is correct |
10 |
Correct |
266 ms |
81368 KB |
Output is correct |
11 |
Correct |
223 ms |
81368 KB |
Output is correct |
12 |
Correct |
246 ms |
81368 KB |
Output is correct |
13 |
Correct |
309 ms |
81368 KB |
Output is correct |
14 |
Correct |
326 ms |
81368 KB |
Output is correct |
15 |
Correct |
279 ms |
81368 KB |
Output is correct |
16 |
Correct |
253 ms |
81368 KB |
Output is correct |
17 |
Correct |
253 ms |
81368 KB |
Output is correct |
18 |
Correct |
273 ms |
81368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
279 ms |
81368 KB |
Output is correct |
2 |
Correct |
296 ms |
81368 KB |
Output is correct |
3 |
Correct |
389 ms |
81368 KB |
Output is correct |
4 |
Correct |
293 ms |
81368 KB |
Output is correct |
5 |
Correct |
343 ms |
81368 KB |
Output is correct |
6 |
Correct |
299 ms |
81368 KB |
Output is correct |
7 |
Correct |
296 ms |
81368 KB |
Output is correct |
8 |
Correct |
279 ms |
81368 KB |
Output is correct |
9 |
Correct |
383 ms |
81368 KB |
Output is correct |
10 |
Correct |
403 ms |
81368 KB |
Output is correct |
11 |
Correct |
386 ms |
81368 KB |
Output is correct |
12 |
Correct |
289 ms |
81368 KB |
Output is correct |
13 |
Correct |
266 ms |
81368 KB |
Output is correct |
14 |
Correct |
299 ms |
81368 KB |
Output is correct |
15 |
Correct |
353 ms |
81368 KB |
Output is correct |
16 |
Correct |
303 ms |
81368 KB |
Output is correct |
17 |
Correct |
346 ms |
81368 KB |
Output is correct |
18 |
Correct |
369 ms |
81368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
81368 KB |
Output is correct |
2 |
Correct |
413 ms |
81368 KB |
Output is correct |
3 |
Correct |
429 ms |
81368 KB |
Output is correct |
4 |
Correct |
353 ms |
81368 KB |
Output is correct |
5 |
Correct |
359 ms |
81368 KB |
Output is correct |
6 |
Correct |
396 ms |
81368 KB |
Output is correct |
7 |
Correct |
386 ms |
81368 KB |
Output is correct |
8 |
Correct |
383 ms |
81368 KB |
Output is correct |
9 |
Correct |
313 ms |
81368 KB |
Output is correct |
10 |
Correct |
373 ms |
81368 KB |
Output is correct |
11 |
Correct |
326 ms |
81368 KB |
Output is correct |
12 |
Correct |
253 ms |
81368 KB |
Output is correct |
13 |
Correct |
399 ms |
81368 KB |
Output is correct |
14 |
Incorrect |
273 ms |
81368 KB |
Output isn't correct |
15 |
Correct |
359 ms |
81368 KB |
Output is correct |
16 |
Correct |
353 ms |
81368 KB |
Output is correct |
17 |
Correct |
393 ms |
81368 KB |
Output is correct |
18 |
Correct |
376 ms |
81368 KB |
Output is correct |
19 |
Correct |
243 ms |
81368 KB |
Output is correct |
20 |
Correct |
413 ms |
81368 KB |
Output is correct |
21 |
Incorrect |
309 ms |
81368 KB |
Output isn't correct |
22 |
Correct |
456 ms |
81368 KB |
Output is correct |
23 |
Correct |
373 ms |
81368 KB |
Output is correct |
24 |
Correct |
303 ms |
81368 KB |
Output is correct |
25 |
Correct |
363 ms |
81368 KB |
Output is correct |
26 |
Correct |
363 ms |
81368 KB |
Output is correct |
27 |
Correct |
459 ms |
81368 KB |
Output is correct |
28 |
Correct |
279 ms |
81368 KB |
Output is correct |
29 |
Correct |
446 ms |
81368 KB |
Output is correct |
30 |
Correct |
443 ms |
81368 KB |
Output is correct |
31 |
Correct |
233 ms |
81368 KB |
Output is correct |
32 |
Correct |
359 ms |
81368 KB |
Output is correct |
33 |
Correct |
329 ms |
81368 KB |
Output is correct |
34 |
Correct |
353 ms |
81368 KB |
Output is correct |
35 |
Correct |
319 ms |
81368 KB |
Output is correct |
36 |
Correct |
429 ms |
81368 KB |
Output is correct |
37 |
Correct |
366 ms |
81368 KB |
Output is correct |
38 |
Correct |
399 ms |
81368 KB |
Output is correct |
39 |
Correct |
319 ms |
81368 KB |
Output is correct |
40 |
Correct |
376 ms |
81368 KB |
Output is correct |
41 |
Correct |
389 ms |
81368 KB |
Output is correct |
42 |
Correct |
363 ms |
81368 KB |
Output is correct |