QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#364842 | #8103. Product | ckiseki# | ML | 226ms | 5952kb | C++20 | 2.2kb | 2024-03-24 16:57:31 | 2024-03-24 16:57:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
const int maxn = 100;
vector<int> sieve(maxn), prs;
for (int i = 2; i < maxn; i++)
if (!sieve[i])
for (int j = i * 2; j < maxn; j += i)
sieve[j] = true;
for (int i = 2; i < maxn; i++)
if (!sieve[i])
prs.push_back(i);
int k;
int64_t N;
vector<int> has(maxn);
// for (int p : prs)
// has[p] = true;
cin >> k;
cin >> N;
for (int i = 0; i < k; i++) {
int p;
cin >> p;
has[p] = true;
}
orange(all(prs));
const int C = 4e8;
vector<int> ns;
ns.reserve(1872208+10);
auto dfs = [&](auto self, size_t i, size_t r, int64_t prod) {
if (i >= r) {
ns.push_back(prod);
return;
}
self(self, i + 1, r, prod);
if (has[prs[i]])
while ((__int128)prod * prs[i] <= C) {
prod *= prs[i];
self(self, i + 1, r, prod);
}
};
dfs(dfs, 0, prs.size(), 1);
debug(ns.size());
sort(all(ns));
const int64_t C2 = 3e10;
int cnt = 0;
int64_t ans = 1;
auto dfs2 = [&](auto self, size_t i, size_t r, int64_t prod) {
auto it = upper_bound(all(ns), N / prod);
if (it != ns.begin()) {
ans = max(ans, *prev(it) * prod);
}
if (i >= r) {
return;
}
// ++cnt;
// if (cnt % 10000 == 0) cerr << cnt << endl;
for (size_t j = i; j < r; j++) {
if (has[prs[j]]) {
auto p = prod;
while ((__int128)p * prs[j] <= C2) {
p *= prs[j];
self(self, j + 1, r, p);
}
}
}
};
dfs2(dfs2, 0, prs.size(), 1);
cout << ans << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3852kb
input:
3 30 2 3 7
output:
28
result:
ok 1 number(s): "28"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3872kb
input:
7 939341491978215167 2 3 19 43 47 53 61
output:
939207819748596228
result:
ok 1 number(s): "939207819748596228"
Test #3:
score: 0
Accepted
time: 105ms
memory: 3880kb
input:
16 997257405471326207 2 3 5 11 19 23 37 41 47 53 59 61 73 79 89 97
output:
997257095125632000
result:
ok 1 number(s): "997257095125632000"
Test #4:
score: 0
Accepted
time: 226ms
memory: 5952kb
input:
21 999404092522162547 2 3 13 17 19 23 29 31 37 41 43 47 59 61 67 71 73 79 83 89 97
output:
999404022916180674
result:
ok 1 number(s): "999404022916180674"
Test #5:
score: 0
Accepted
time: 7ms
memory: 3628kb
input:
6 969452367537798143 2 3 5 7 11 13
output:
969402569554298880
result:
ok 1 number(s): "969402569554298880"
Test #6:
score: -100
Memory Limit Exceeded
input:
25 999949383078942015 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
output:
999949379900286375