This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#pragma GCC optimize("Ofast")
template<typename T> using v = vector<T>;
template<typename T, typename U> using hmap = __gnu_pbds::gp_hash_table<T, U>;
//#define int long long
typedef long double ld;
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0 //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt" : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
#define check(a) put #a << ": " << a << endl;
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg) ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg arg,Args... args){put (arg)<<" ";print(args...);}
void debug(){eol;} template<typename Arg,typename... Args> void debug(Arg arg,Args... args){put (arg)<<" ";debug(args...);}
int getInt(){int a; get a; return a;}
//code goes here
const long long N = 1e7 + 1;
vint erato[N];
int dp[N];
void run() {
int m, q;
read(m, q);
int p[m];
rep(i, 0, m) {
get p[i];
if (p[i] > 30)
for (int j = 1; j * p[i] < N; j++)
erato[j * p[i]].pb(i);
}
long long mul = 1;
rep(i, 0, m) {
mul *= p[i];
if (mul > N) {
mul = 1e9;
break;
}
}
vint primes;
for (int i : {2, 3, 5, 7, 11, 13, 17, 23, 29}) {
for (int j : p)
if (i == j)
goto nxt;
primes.pb(i);
nxt:;
}
dp[0] = 0;
int cur[m];
rep(i, 0, m)
cur[i] = 1;
int pen = 0;
multiset<int> mx;
rep(i, 0, m)
mx.insert(1);
rep(i, 1, min(N, mul)) {
for (int j : erato[i]) {
mx.erase(mx.find(cur[j]));
cur[j] = -pen;
mx.insert(cur[j]);
}
int d = (*mx.rbegin()) + pen;
for (int j : primes)
d = max(d, i % j);
dp[i] = dp[i - d] + 1;
pen++;
}
rep(i, 0, q) {
int n;
get n;
if (n >= mul)
put "oo";
else
put dp[n];
eol;
}
}
int32_t main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); put fixed; put setprecision(15); run(); 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... |