#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int dp[N*10],ile[N*10],zap[N],t[N],last[N*10];
bitset<N*10>byl;
void solve(){
int n,m;
cin>>m>>n;
for(int i=1;i<=m;i++) cin>>t[i];
int maxi=0;
for(int i=1;i<=n;i++){
cin>>zap[i];
maxi=max(maxi,zap[i]);
}
for(int i=1;i<=m;i++) byl[t[i]]=1;
for(int i=2;i<=maxi;i++){
if(last[i]) continue;
for(int j=i;j<=maxi;j+=i) last[j]=i;
}
deque<int> curr;
curr.push_back(0);
ile[0]=m;
for(int i=1;i<=maxi;i++){
int xd=i,il=0,pop=0;
while(xd>1){
int u=last[xd];
if(byl[u] and pop!=u) ile[((i/u)-1)*u]--,il++;
pop=u;
xd/=u;
}
while(curr.size() and !ile[curr[0]]) curr.pop_front();
if(!curr.size()) dp[i]=INFi;
else dp[i]=min(dp[curr[0]]+1,INFi);
curr.push_back(i);
ile[i]=il;
}
for(int i=1;i<=n;i++){
if(dp[zap[i]]==INFi) cout<<"oo\n";
else cout<<dp[zap[i]]<<"\n";
}
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
532 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
647 ms |
120360 KB |
Output is correct |
2 |
Correct |
588 ms |
144468 KB |
Output is correct |
3 |
Correct |
418 ms |
66332 KB |
Output is correct |
4 |
Correct |
671 ms |
106888 KB |
Output is correct |
5 |
Correct |
246 ms |
36556 KB |
Output is correct |
6 |
Correct |
252 ms |
41312 KB |
Output is correct |
7 |
Correct |
659 ms |
120412 KB |
Output is correct |
8 |
Correct |
259 ms |
44492 KB |
Output is correct |
9 |
Correct |
212 ms |
36572 KB |
Output is correct |
10 |
Correct |
433 ms |
66396 KB |
Output is correct |
11 |
Correct |
887 ms |
121724 KB |
Output is correct |
12 |
Correct |
713 ms |
100856 KB |
Output is correct |
13 |
Correct |
673 ms |
118936 KB |
Output is correct |
14 |
Correct |
675 ms |
106928 KB |
Output is correct |
15 |
Correct |
281 ms |
41544 KB |
Output is correct |
16 |
Correct |
676 ms |
144412 KB |
Output is correct |
17 |
Correct |
908 ms |
116588 KB |
Output is correct |
18 |
Correct |
939 ms |
139096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
959 ms |
122536 KB |
Output is correct |
2 |
Correct |
921 ms |
121300 KB |
Output is correct |
3 |
Correct |
660 ms |
87856 KB |
Output is correct |
4 |
Correct |
884 ms |
118976 KB |
Output is correct |
5 |
Correct |
692 ms |
137684 KB |
Output is correct |
6 |
Correct |
931 ms |
119268 KB |
Output is correct |
7 |
Correct |
574 ms |
96000 KB |
Output is correct |
8 |
Correct |
932 ms |
122488 KB |
Output is correct |
9 |
Correct |
925 ms |
122628 KB |
Output is correct |
10 |
Correct |
836 ms |
118336 KB |
Output is correct |
11 |
Correct |
777 ms |
118376 KB |
Output is correct |
12 |
Correct |
901 ms |
118436 KB |
Output is correct |
13 |
Correct |
456 ms |
64400 KB |
Output is correct |
14 |
Correct |
508 ms |
72960 KB |
Output is correct |
15 |
Correct |
931 ms |
118216 KB |
Output is correct |
16 |
Correct |
884 ms |
118312 KB |
Output is correct |
17 |
Correct |
879 ms |
121584 KB |
Output is correct |
18 |
Correct |
934 ms |
121148 KB |
Output is correct |
19 |
Correct |
731 ms |
121068 KB |
Output is correct |
20 |
Correct |
627 ms |
87704 KB |
Output is correct |
21 |
Correct |
854 ms |
118732 KB |
Output is correct |
22 |
Correct |
935 ms |
125208 KB |
Output is correct |
23 |
Correct |
701 ms |
122752 KB |
Output is correct |
24 |
Correct |
679 ms |
118864 KB |
Output is correct |
25 |
Correct |
914 ms |
118664 KB |
Output is correct |
26 |
Correct |
875 ms |
118892 KB |
Output is correct |
27 |
Correct |
623 ms |
90984 KB |
Output is correct |
28 |
Correct |
751 ms |
119216 KB |
Output is correct |
29 |
Correct |
865 ms |
125308 KB |
Output is correct |
30 |
Correct |
862 ms |
122836 KB |
Output is correct |
31 |
Correct |
725 ms |
119768 KB |
Output is correct |
32 |
Correct |
750 ms |
118876 KB |
Output is correct |
33 |
Correct |
672 ms |
119128 KB |
Output is correct |
34 |
Correct |
603 ms |
95964 KB |
Output is correct |
35 |
Correct |
733 ms |
119164 KB |
Output is correct |
36 |
Correct |
943 ms |
125268 KB |
Output is correct |
37 |
Correct |
701 ms |
137636 KB |
Output is correct |
38 |
Correct |
991 ms |
119072 KB |
Output is correct |
39 |
Correct |
704 ms |
118844 KB |
Output is correct |
40 |
Correct |
958 ms |
119188 KB |
Output is correct |
41 |
Correct |
659 ms |
113212 KB |
Output is correct |
42 |
Correct |
899 ms |
118700 KB |
Output is correct |