#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
#define N 20000005
ll n, m, q, a[N], ad[N], t;
int main () {
ios::sync_with_stdio(0);cin.tie(0);
cin >> m >> q;
for(int i = 1;i<=m;i++){
cin >> a[i];
for(int j = a[i]; j <= 1e7 + 1; j += a[i]) {
ad[j - 1] = max(ad[j - 1], a[i] - 1);
}
ad[10000000] = max(ad[10000000],(10000000%a[i]));
}
for(int i = 1e7; i >= 1; i--) {
ad[i] = max(ad[i],ad[i+1] - 1);
}
for(int i = 1; i <= q; i++) {
int x, cnt = 0;
cin >> x;
bool tr = 0;
while(x > 0) {
t = x;
x -= ad[x];
cnt++;
if(t == x) {
tr = 1;
break;
}
}
if(tr) {
cout << "oo\n";
continue;
}
cout << cnt << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |