This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 1e7 + 1;
int f[N];
int g[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int m; cin >> m;
int q; cin >> q;
for(int i = 1 ; i < N ; ++i) f[i] = i;
for(int i = 0 ; i < m ; ++i) {
int x; cin >> x;
for(int j = x ; j < N ; j += x)
f[j - 1] = min(f[j - 1],j - x);
f[N - 1] = min(f[N - 1],(N - 1) / x * x);
}
for(int i = N - 2 ; i ; --i)
f[i] = min(f[i],f[i + 1]);
for(int i = 1 ; i < N ; ++i) {
if (f[i] == i)
g[i] = 1e9;
else
g[i] = g[f[i]] + 1;
}
//for(int i = 1 ; i < 10 ; ++i)
// cout << f[i] << " ";
//cout << "\n";
for(int i = 0 ; i < q ; ++i) {
int x; cin >> x;
if (g[x] >= 1e9)
cout << "oo\n";
else
cout << g[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... |