#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<=n;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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
340 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 |
1 ms |
472 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 |
464 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
610 ms |
157164 KB |
Output isn't correct |
2 |
Incorrect |
537 ms |
144012 KB |
Output isn't correct |
3 |
Incorrect |
288 ms |
75636 KB |
Output isn't correct |
4 |
Incorrect |
549 ms |
143608 KB |
Output isn't correct |
5 |
Incorrect |
161 ms |
42204 KB |
Output isn't correct |
6 |
Incorrect |
204 ms |
55288 KB |
Output isn't correct |
7 |
Incorrect |
591 ms |
157252 KB |
Output isn't correct |
8 |
Incorrect |
211 ms |
59760 KB |
Output isn't correct |
9 |
Incorrect |
154 ms |
42272 KB |
Output isn't correct |
10 |
Incorrect |
300 ms |
75648 KB |
Output isn't correct |
11 |
Incorrect |
624 ms |
159108 KB |
Output isn't correct |
12 |
Incorrect |
531 ms |
135628 KB |
Output isn't correct |
13 |
Incorrect |
608 ms |
157404 KB |
Output isn't correct |
14 |
Incorrect |
583 ms |
143628 KB |
Output isn't correct |
15 |
Incorrect |
189 ms |
51428 KB |
Output isn't correct |
16 |
Incorrect |
543 ms |
144152 KB |
Output isn't correct |
17 |
Incorrect |
613 ms |
156724 KB |
Output isn't correct |
18 |
Incorrect |
651 ms |
159824 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
909 ms |
159888 KB |
Output isn't correct |
2 |
Incorrect |
851 ms |
159704 KB |
Output isn't correct |
3 |
Correct |
605 ms |
88616 KB |
Output is correct |
4 |
Correct |
849 ms |
119504 KB |
Output is correct |
5 |
Correct |
678 ms |
139136 KB |
Output is correct |
6 |
Correct |
913 ms |
119708 KB |
Output is correct |
7 |
Incorrect |
542 ms |
114092 KB |
Output isn't correct |
8 |
Incorrect |
886 ms |
159832 KB |
Output isn't correct |
9 |
Incorrect |
865 ms |
159796 KB |
Output isn't correct |
10 |
Correct |
796 ms |
118288 KB |
Output is correct |
11 |
Correct |
748 ms |
118628 KB |
Output is correct |
12 |
Correct |
891 ms |
118512 KB |
Output is correct |
13 |
Correct |
440 ms |
65148 KB |
Output is correct |
14 |
Correct |
491 ms |
73692 KB |
Output is correct |
15 |
Correct |
868 ms |
118640 KB |
Output is correct |
16 |
Correct |
865 ms |
118448 KB |
Output is correct |
17 |
Incorrect |
831 ms |
159452 KB |
Output isn't correct |
18 |
Incorrect |
848 ms |
159624 KB |
Output isn't correct |
19 |
Correct |
692 ms |
121212 KB |
Output is correct |
20 |
Correct |
599 ms |
88568 KB |
Output is correct |
21 |
Correct |
833 ms |
119524 KB |
Output is correct |
22 |
Correct |
899 ms |
126808 KB |
Output is correct |
23 |
Correct |
689 ms |
123652 KB |
Output is correct |
24 |
Correct |
651 ms |
119540 KB |
Output is correct |
25 |
Correct |
908 ms |
119572 KB |
Output is correct |
26 |
Correct |
858 ms |
119548 KB |
Output is correct |
27 |
Incorrect |
589 ms |
114024 KB |
Output isn't correct |
28 |
Correct |
693 ms |
120076 KB |
Output is correct |
29 |
Correct |
813 ms |
126776 KB |
Output is correct |
30 |
Correct |
780 ms |
124104 KB |
Output is correct |
31 |
Correct |
694 ms |
120268 KB |
Output is correct |
32 |
Correct |
729 ms |
119428 KB |
Output is correct |
33 |
Correct |
649 ms |
119852 KB |
Output is correct |
34 |
Incorrect |
550 ms |
114048 KB |
Output isn't correct |
35 |
Correct |
693 ms |
120004 KB |
Output is correct |
36 |
Correct |
926 ms |
126632 KB |
Output is correct |
37 |
Correct |
670 ms |
139016 KB |
Output is correct |
38 |
Correct |
886 ms |
119664 KB |
Output is correct |
39 |
Correct |
670 ms |
119756 KB |
Output is correct |
40 |
Correct |
890 ms |
120020 KB |
Output is correct |
41 |
Correct |
584 ms |
114224 KB |
Output is correct |
42 |
Correct |
851 ms |
119688 KB |
Output is correct |