#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;
//Note to self: Check for overflow
const int N=10'000'000;
int dp[N+7];
int lud[N+7]; //largest divisor
int main()
{
FAST;
int m,q; cin>>m>>q;
vector<int> prost(m);
ff(i,0,m) cin>>prost[i];
fff(i,1,N) dp[i]=mod;
for (auto p : prost)
{
for (int i=0;i<=N/p;i++) lud[i*p]=p;
}
int dokle0=-1,dokle1=-1,okle=0;
fff(i,0,N)
{
if (i)
{
if (dokle0>=i) dp[i]=dp[i-1];
else
{
if (dokle1>=i) dp[i]=dp[i-1]+1;
{
dokle0=dokle1,dokle1=-1;
}
}
}
dokle1=max(dokle1,i+lud[i]-1);
}
//fff(i,0,10) cout<<i<<": "<<dp[i]<<endl;
while (q--)
{
int nj; cin>>nj;
if (dp[nj]>N+3) cout<<"oo\n";
else cout<<dp[nj]<<"\n";
}
}
//Note to self: Check for overflow
Compilation message
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:57:29: warning: unused variable 'okle' [-Wunused-variable]
57 | int dokle0=-1,dokle1=-1,okle=0;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
78552 KB |
Output is correct |
2 |
Correct |
72 ms |
78588 KB |
Output is correct |
3 |
Correct |
74 ms |
78584 KB |
Output is correct |
4 |
Correct |
99 ms |
78652 KB |
Output is correct |
5 |
Correct |
70 ms |
78560 KB |
Output is correct |
6 |
Correct |
61 ms |
78496 KB |
Output is correct |
7 |
Correct |
82 ms |
78760 KB |
Output is correct |
8 |
Correct |
78 ms |
78516 KB |
Output is correct |
9 |
Correct |
95 ms |
78584 KB |
Output is correct |
10 |
Correct |
96 ms |
78588 KB |
Output is correct |
11 |
Correct |
88 ms |
78588 KB |
Output is correct |
12 |
Correct |
58 ms |
78608 KB |
Output is correct |
13 |
Correct |
145 ms |
78592 KB |
Output is correct |
14 |
Correct |
156 ms |
78628 KB |
Output is correct |
15 |
Correct |
80 ms |
78576 KB |
Output is correct |
16 |
Correct |
88 ms |
78580 KB |
Output is correct |
17 |
Correct |
75 ms |
78668 KB |
Output is correct |
18 |
Correct |
63 ms |
78620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
78716 KB |
Output is correct |
2 |
Correct |
112 ms |
79632 KB |
Output is correct |
3 |
Correct |
188 ms |
79296 KB |
Output is correct |
4 |
Correct |
84 ms |
78664 KB |
Output is correct |
5 |
Correct |
131 ms |
79052 KB |
Output is correct |
6 |
Correct |
78 ms |
78536 KB |
Output is correct |
7 |
Correct |
69 ms |
78628 KB |
Output is correct |
8 |
Correct |
84 ms |
78588 KB |
Output is correct |
9 |
Correct |
157 ms |
79248 KB |
Output is correct |
10 |
Correct |
192 ms |
79328 KB |
Output is correct |
11 |
Correct |
174 ms |
78932 KB |
Output is correct |
12 |
Correct |
109 ms |
78600 KB |
Output is correct |
13 |
Correct |
79 ms |
78612 KB |
Output is correct |
14 |
Correct |
94 ms |
78496 KB |
Output is correct |
15 |
Correct |
151 ms |
78924 KB |
Output is correct |
16 |
Correct |
78 ms |
79636 KB |
Output is correct |
17 |
Correct |
162 ms |
78608 KB |
Output is correct |
18 |
Correct |
147 ms |
79624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
79412 KB |
Output is correct |
2 |
Correct |
209 ms |
79300 KB |
Output is correct |
3 |
Correct |
189 ms |
79680 KB |
Output is correct |
4 |
Correct |
130 ms |
79472 KB |
Output is correct |
5 |
Correct |
98 ms |
80632 KB |
Output is correct |
6 |
Correct |
203 ms |
79580 KB |
Output is correct |
7 |
Correct |
142 ms |
80260 KB |
Output is correct |
8 |
Correct |
163 ms |
79472 KB |
Output is correct |
9 |
Correct |
161 ms |
79412 KB |
Output is correct |
10 |
Correct |
130 ms |
78716 KB |
Output is correct |
11 |
Correct |
108 ms |
78836 KB |
Output is correct |
12 |
Correct |
144 ms |
78924 KB |
Output is correct |
13 |
Correct |
199 ms |
79800 KB |
Output is correct |
14 |
Correct |
121 ms |
79820 KB |
Output is correct |
15 |
Correct |
160 ms |
78840 KB |
Output is correct |
16 |
Correct |
199 ms |
78812 KB |
Output is correct |
17 |
Correct |
142 ms |
79172 KB |
Output is correct |
18 |
Correct |
207 ms |
79300 KB |
Output is correct |
19 |
Correct |
77 ms |
78792 KB |
Output is correct |
20 |
Correct |
197 ms |
79668 KB |
Output is correct |
21 |
Correct |
134 ms |
80008 KB |
Output is correct |
22 |
Correct |
243 ms |
80636 KB |
Output is correct |
23 |
Correct |
130 ms |
79840 KB |
Output is correct |
24 |
Correct |
97 ms |
79528 KB |
Output is correct |
25 |
Correct |
153 ms |
79588 KB |
Output is correct |
26 |
Correct |
149 ms |
79468 KB |
Output is correct |
27 |
Correct |
219 ms |
80136 KB |
Output is correct |
28 |
Correct |
99 ms |
79680 KB |
Output is correct |
29 |
Correct |
198 ms |
80632 KB |
Output is correct |
30 |
Correct |
246 ms |
80328 KB |
Output is correct |
31 |
Correct |
104 ms |
79440 KB |
Output is correct |
32 |
Correct |
135 ms |
79600 KB |
Output is correct |
33 |
Correct |
86 ms |
79484 KB |
Output is correct |
34 |
Correct |
147 ms |
80204 KB |
Output is correct |
35 |
Correct |
108 ms |
79592 KB |
Output is correct |
36 |
Correct |
232 ms |
80496 KB |
Output is correct |
37 |
Correct |
113 ms |
80616 KB |
Output is correct |
38 |
Correct |
200 ms |
79620 KB |
Output is correct |
39 |
Correct |
124 ms |
79596 KB |
Output is correct |
40 |
Correct |
183 ms |
79624 KB |
Output is correct |
41 |
Correct |
137 ms |
80252 KB |
Output is correct |
42 |
Correct |
218 ms |
79728 KB |
Output is correct |