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;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define foxr1(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
int n, q, x, c, lo=(1 << 30), pre[10000005], dp[10000005];
vector<int> f[10000005];
bool p[10000005], u[10000005];
int main(){
cin.tie(0);
cin.sync_with_stdio(0);
cout.tie(0);
cout.sync_with_stdio(0);
cin >> n >> q;
fox(l, n){
cin >> x;
p[x]=1;
lo=min(lo, 10000000/x*x);
}
for(int l=2; l<=10000000; ++l){
if (u[l]) continue;
for (int l2=l; l2<=10000000; l2+=l){
if (p[l]) f[l2].pb(l);
u[l2]=1;
}
}
foxr1(l, 10000000){
pre[l]=lo;
fox(l2, f[l].size()){
lo=min(lo, l-f[l][l2]);
}
}
fox1(l, 10000000){
if (pre[l]==l) dp[l]=(1 << 30);
dp[l]=dp[pre[l]]+1;
}
fox(l, q){
cin >> x;
if (dp[x]>=(1 << 30)){
cout << "oo\n";
}
else {
cout << dp[x] << endl;
}
}
return 0;
}
Compilation message (stderr)
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
^
brunhilda.cpp:49:9: note: in expansion of macro 'fox'
fox(l2, f[l].size()){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |