# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535486 | Baray | Brunhilda’s Birthday (BOI13_brunhilda) | C++17 | 443 ms | 159368 KiB |
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<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
#define N 10000005
int sieve[N], cost[N];
int n, q;
signed main() {
cin >> n >> q;
vector<int> a(n);
int child, l = 1, mx = 0, p;
for (int i = 0; i < n; i++) {
cin >> p;
mx = max(mx, p);
for (int j = p; j < N; j += p) {
sieve[j] = p;
}
}
int cur = mx, next = 0, cur_cost = 1;
for (int i = 0; i < N; i++) {
if (i >= cur) {
if (next > cur) {
cur = next;
cur_cost++;
}
else break;
}
cost[i] = cur_cost;
if (sieve[i]) next = max(next, i + sieve[i]);
}
while (q--) {
cin >> p;
if (cost[p] == 0) {
cout << "oo\n";
continue;
}
cout << cost[p] << "\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |