#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;
for (l2=l; 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:53:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &x);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
416 ms |
81368 KB |
Output isn't correct |
2 |
Correct |
446 ms |
81368 KB |
Output is correct |
3 |
Incorrect |
453 ms |
81368 KB |
Output isn't correct |
4 |
Correct |
406 ms |
81368 KB |
Output is correct |
5 |
Correct |
426 ms |
81368 KB |
Output is correct |
6 |
Incorrect |
453 ms |
81368 KB |
Output isn't correct |
7 |
Incorrect |
449 ms |
81368 KB |
Output isn't correct |
8 |
Incorrect |
479 ms |
81368 KB |
Output isn't correct |
9 |
Correct |
429 ms |
81368 KB |
Output is correct |
10 |
Correct |
429 ms |
81368 KB |
Output is correct |
11 |
Incorrect |
446 ms |
81368 KB |
Output isn't correct |
12 |
Correct |
433 ms |
81368 KB |
Output is correct |
13 |
Correct |
439 ms |
81368 KB |
Output is correct |
14 |
Correct |
439 ms |
81368 KB |
Output is correct |
15 |
Correct |
439 ms |
81368 KB |
Output is correct |
16 |
Correct |
393 ms |
81368 KB |
Output is correct |
17 |
Correct |
389 ms |
81368 KB |
Output is correct |
18 |
Correct |
386 ms |
81368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
363 ms |
81368 KB |
Output is correct |
2 |
Correct |
373 ms |
81368 KB |
Output is correct |
3 |
Correct |
369 ms |
81368 KB |
Output is correct |
4 |
Correct |
393 ms |
81368 KB |
Output is correct |
5 |
Correct |
439 ms |
81368 KB |
Output is correct |
6 |
Correct |
446 ms |
81368 KB |
Output is correct |
7 |
Correct |
459 ms |
81368 KB |
Output is correct |
8 |
Correct |
433 ms |
81368 KB |
Output is correct |
9 |
Correct |
406 ms |
81368 KB |
Output is correct |
10 |
Correct |
443 ms |
81368 KB |
Output is correct |
11 |
Correct |
423 ms |
81368 KB |
Output is correct |
12 |
Correct |
439 ms |
81368 KB |
Output is correct |
13 |
Correct |
436 ms |
81368 KB |
Output is correct |
14 |
Correct |
423 ms |
81368 KB |
Output is correct |
15 |
Correct |
419 ms |
81368 KB |
Output is correct |
16 |
Correct |
323 ms |
81368 KB |
Output is correct |
17 |
Correct |
443 ms |
81368 KB |
Output is correct |
18 |
Correct |
369 ms |
81368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
476 ms |
81368 KB |
Output is correct |
2 |
Correct |
456 ms |
81368 KB |
Output is correct |
3 |
Correct |
466 ms |
81368 KB |
Output is correct |
4 |
Correct |
393 ms |
81368 KB |
Output is correct |
5 |
Correct |
489 ms |
81368 KB |
Output is correct |
6 |
Correct |
476 ms |
81368 KB |
Output is correct |
7 |
Correct |
463 ms |
81368 KB |
Output is correct |
8 |
Correct |
466 ms |
81368 KB |
Output is correct |
9 |
Correct |
419 ms |
81368 KB |
Output is correct |
10 |
Correct |
396 ms |
81368 KB |
Output is correct |
11 |
Correct |
446 ms |
81368 KB |
Output is correct |
12 |
Correct |
399 ms |
81368 KB |
Output is correct |
13 |
Correct |
413 ms |
81368 KB |
Output is correct |
14 |
Incorrect |
409 ms |
81368 KB |
Output isn't correct |
15 |
Correct |
446 ms |
81368 KB |
Output is correct |
16 |
Correct |
439 ms |
81368 KB |
Output is correct |
17 |
Correct |
453 ms |
81368 KB |
Output is correct |
18 |
Correct |
456 ms |
81368 KB |
Output is correct |
19 |
Correct |
483 ms |
81368 KB |
Output is correct |
20 |
Correct |
476 ms |
81368 KB |
Output is correct |
21 |
Incorrect |
496 ms |
81368 KB |
Output isn't correct |
22 |
Correct |
426 ms |
81368 KB |
Output is correct |
23 |
Correct |
396 ms |
81368 KB |
Output is correct |
24 |
Correct |
479 ms |
81368 KB |
Output is correct |
25 |
Correct |
483 ms |
81368 KB |
Output is correct |
26 |
Correct |
479 ms |
81368 KB |
Output is correct |
27 |
Correct |
503 ms |
81368 KB |
Output is correct |
28 |
Correct |
466 ms |
81368 KB |
Output is correct |
29 |
Correct |
513 ms |
81368 KB |
Output is correct |
30 |
Correct |
473 ms |
81368 KB |
Output is correct |
31 |
Correct |
483 ms |
81368 KB |
Output is correct |
32 |
Correct |
493 ms |
81368 KB |
Output is correct |
33 |
Correct |
469 ms |
81368 KB |
Output is correct |
34 |
Correct |
466 ms |
81368 KB |
Output is correct |
35 |
Correct |
453 ms |
81368 KB |
Output is correct |
36 |
Correct |
506 ms |
81368 KB |
Output is correct |
37 |
Correct |
526 ms |
81368 KB |
Output is correct |
38 |
Correct |
483 ms |
81368 KB |
Output is correct |
39 |
Correct |
473 ms |
81368 KB |
Output is correct |
40 |
Correct |
469 ms |
81368 KB |
Output is correct |
41 |
Correct |
463 ms |
81368 KB |
Output is correct |
42 |
Correct |
453 ms |
81368 KB |
Output is correct |