#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 40000005
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
ll n, m, q, vis[N], p = -1, vip[N];
vector <ll> a;
int main () {
ios::sync_with_stdio(0);cin.tie(0);
cin >> m >> q;
for(ll i = 1;i<=m;i++) {
ll x;
cin >> x;
if(vip[x]) continue;
vip[x] = 1;
a.pb(x);
}
for(auto i : a) {
for(ll j = i; j <= 1e7; j += i) {
vis[j]++;
if(vis[j] == sz(a)) {
p = j;
break;
}
}
if(p != -1) break;
}
sort(a.rbegin(),a.rend());
for(int j = 1; j <= q; j++) {
ll x, cnt = 0, tr = 0;
cin >> x;
if(p > 0 && x % p == 0) {
cout << "oo\n";
continue;
}
while(x) {
if(a[0] > x) {
cnt++;
break;
}
ll mx = INT_MAX;
for(auto i : a) {
if(mx > (x / i) * i) mx = (x / i) * i;
if(i - 1 <= x - mx) break;
}
if(mx == x) {
tr = 1;
break;
}
x = mx;
cnt++;
}
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... |