#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, vip[N];
string s, g, h;
vector <ll> a;
int main () {
ios::sync_with_stdio(0);cin.tie(0);
cin >> m >> q;
for(int i= 1;i<=m;i++) {
ll x;
cin >> x;
if(vip[x]) continue;
vip[x] = 1;
for(ll j = x; j <= 1e7; j += x) {
vis[j]++;
}
a.pb(x);
}
for(ll j = 2; j <= 1e7; j++) {
if(vis[j] == m) {
p = j;
break;
}
}
sort(a.rbegin(),a.rend());
for(int j = 1;j<=q;j++) {
int x, cnt = 0, tr = 0;
cin >> x;
if(x % p == 0) {
cout << "oo\n";
continue;
}
while(x != 0) {
if(a[0] > x) {
cnt++;
break;
}
int mx = INT_MAX;
for(auto i : a) {
if(mx > (x / i) * i) mx = (x / i) * i;
if(i - 1 <= x - mx) break;
}
x = mx;
cnt++;
}
if(!tr)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... |