#include <bits/stdc++.h> using namespace std; int64_t SQR = 0, ans = 0; vector<int> rec_primes, gen_primes; vector<int> all; int query(int rem) { auto it = upper_bound(all.begin(), all.end(), rem); it -= 1; return (*it); } void rec(int poz, int64_t rem, int64_t now) { if(poz == (int) rec_primes.size()) { if(now >= SQR) { ans = max(ans, now * query(rem)); } return; } int64_t here = 1; int64_t here_rem = rem; while(here_rem) { rec(poz + 1, here_rem, here * now); here *= rec_primes[poz]; here_rem /= rec_primes[poz]; } } void generate(int poz, int64_t rem, int64_t now) { if(poz == (int) gen_primes.size()) { all.push_back(now); return; } int64_t here = 1; int64_t here_rem = rem; while(here_rem) { generate(poz + 1, here_rem, here * now); here *= gen_primes[poz]; here_rem /= gen_primes[poz]; } } int main() { //ifstream cin("ilo.in"); int k; cin >> k; int64_t n; cin >> n; SQR = (int64_t) sqrt(n); while(SQR * SQR < n) SQR += 1; vector<int> p(k, 0); for(int i = 0; i < k; ++i) { cin >> p[i]; } sort(p.begin(), p.end()); int left = min(9, k / 2); vector<int> left_primes, right_primes; for(int i = 0; i < k; ++i) { if(i < left) { left_primes.push_back(p[i]); } else { right_primes.push_back(p[i]); } } rec_primes = left_primes; gen_primes = right_primes; generate(0, SQR, 1); sort(all.begin(), all.end()); rec(0, n, 1); all.clear(); rec_primes = right_primes; gen_primes = left_primes; generate(0, SQR, 1); sort(all.begin(), all.end()); rec(0, n, 1); cout << ans << "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | #include <bits/stdc++.h> using namespace std; int64_t SQR = 0, ans = 0; vector<int> rec_primes, gen_primes; vector<int> all; int query(int rem) { auto it = upper_bound(all.begin(), all.end(), rem); it -= 1; return (*it); } void rec(int poz, int64_t rem, int64_t now) { if(poz == (int) rec_primes.size()) { if(now >= SQR) { ans = max(ans, now * query(rem)); } return; } int64_t here = 1; int64_t here_rem = rem; while(here_rem) { rec(poz + 1, here_rem, here * now); here *= rec_primes[poz]; here_rem /= rec_primes[poz]; } } void generate(int poz, int64_t rem, int64_t now) { if(poz == (int) gen_primes.size()) { all.push_back(now); return; } int64_t here = 1; int64_t here_rem = rem; while(here_rem) { generate(poz + 1, here_rem, here * now); here *= gen_primes[poz]; here_rem /= gen_primes[poz]; } } int main() { //ifstream cin("ilo.in"); int k; cin >> k; int64_t n; cin >> n; SQR = (int64_t) sqrt(n); while(SQR * SQR < n) SQR += 1; vector<int> p(k, 0); for(int i = 0; i < k; ++i) { cin >> p[i]; } sort(p.begin(), p.end()); int left = min(9, k / 2); vector<int> left_primes, right_primes; for(int i = 0; i < k; ++i) { if(i < left) { left_primes.push_back(p[i]); } else { right_primes.push_back(p[i]); } } rec_primes = left_primes; gen_primes = right_primes; generate(0, SQR, 1); sort(all.begin(), all.end()); rec(0, n, 1); all.clear(); rec_primes = right_primes; gen_primes = left_primes; generate(0, SQR, 1); sort(all.begin(), all.end()); rec(0, n, 1); cout << ans << "\n"; } |