#include <iostream>
#include <vector>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int m, q;
cin >> m >> q;
vector<int> p (m);
//quickly check if the product > 10^7
int product = 1;
for(int i = 0; i < m; ++i) {
cin >> p[i];
if(product <= 10000000) product *= p[i];
}
int n;
for(int i = 0; i < q; ++i) {
cin >> n;
if(n >= product) {
cout << "oo\n";
continue;
}
//loop time
int counter = 0;
while(n >= p[m-1]) {
counter++;
//find the maximum prime
int newn = n;
for(int i = m-1; i >= 0; --i) {
if(n % p[i] != 0) {
newn = min(newn, n/p[i]*p[i]);
}
}
n = newn;
}
cout << counter+1 << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |