#include <bits/stdc++.h>
using namespace std;
int n, q;
vector <int> a, dp(10000000, -1);
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> q;
a.resize(n+1);
long long s = 1;
for(int i = 1; i <= n; i++){
cin >> a[i];
if(s > 1e7) continue;
s *= a[i];
}
dp[0] = 0;
for(int i = 1; i <= (1e7)/n; i++){
int k = 0;
for(int j = 1; j <= n; j++){
k = max(k, (i%a[j]));
}
if(k == 0) continue;
dp[i] = dp[i-k] + 1;
}
while(q--){
int x;
cin >> x;
if(x >= s) cout << "oo\n";
else cout << dp[x] << "\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... |