#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int k, p[30]; long long n, res; int s; int tab[900000], ts; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> k >> n; s = sqrt(n)+5; for (int i=1; i<=k; i++) cin >> p[i]; sort(p+1, p+k+1); vector<int> dp_set, rest; for (int i=1; i<=k; i++) dp_set.push_back(p[i]); reverse(dp_set.begin(), dp_set.end()); // vector<int> prev = {1}, next; bool twos = false; if (dp_set.back() == 2) { dp_set.pop_back(); twos = true; } tab[ts++] = 1; for (int p: dp_set) { long long pp = p; int os = ts; vector<int> ends = {ts}; while (pp <= s) { long long highest = s / pp; int ms = ts; // int size = 0; // for (int j=0; j<prev.size() && prev[j] <= highest; j++) size++; // int oldsize = next.size(); // next.resize(oldsize+size); for (int j=0; j<os && tab[j] <= highest; j++) tab[ts++] = tab[j] * pp; ends.push_back(ts); pp *= p; } for (int i=0; i<ends.size()-1; i++) inplace_merge(tab, tab+ends[i], tab+ends[i+1]); // prev.clear(); // prev.swap(next); // cerr << p << ": " << ts << endl; } // if (twos) dp_set.push_back(2); // int start = ts-1; for (int t=0; t<=(twos?60:0); t++) { if ((n>>t) == 0) break; res = max(res, (1LL<<t)); // long long high = n >> t; // while (tab[start] > high) start--; while (tab[ts-1] * (long long)tab[ts-1] > (n>>t)) ts--; for (long long p: dp_set) { int i = ts-1; // if (t == 16) cerr << "p = " << p << endl; if (p > (n>>t)) continue; p <<= t; long long v = n / p; for (int j=0; j<ts; j++) { long long x = tab[j]; while (i >= 0 && x * tab[i] > v) i--; if (i < 0) break; res = max(res, x * tab[i] * p); } } } cout << res << "\n"; return 0; }
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 | #include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int k, p[30]; long long n, res; int s; int tab[900000], ts; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> k >> n; s = sqrt(n)+5; for (int i=1; i<=k; i++) cin >> p[i]; sort(p+1, p+k+1); vector<int> dp_set, rest; for (int i=1; i<=k; i++) dp_set.push_back(p[i]); reverse(dp_set.begin(), dp_set.end()); // vector<int> prev = {1}, next; bool twos = false; if (dp_set.back() == 2) { dp_set.pop_back(); twos = true; } tab[ts++] = 1; for (int p: dp_set) { long long pp = p; int os = ts; vector<int> ends = {ts}; while (pp <= s) { long long highest = s / pp; int ms = ts; // int size = 0; // for (int j=0; j<prev.size() && prev[j] <= highest; j++) size++; // int oldsize = next.size(); // next.resize(oldsize+size); for (int j=0; j<os && tab[j] <= highest; j++) tab[ts++] = tab[j] * pp; ends.push_back(ts); pp *= p; } for (int i=0; i<ends.size()-1; i++) inplace_merge(tab, tab+ends[i], tab+ends[i+1]); // prev.clear(); // prev.swap(next); // cerr << p << ": " << ts << endl; } // if (twos) dp_set.push_back(2); // int start = ts-1; for (int t=0; t<=(twos?60:0); t++) { if ((n>>t) == 0) break; res = max(res, (1LL<<t)); // long long high = n >> t; // while (tab[start] > high) start--; while (tab[ts-1] * (long long)tab[ts-1] > (n>>t)) ts--; for (long long p: dp_set) { int i = ts-1; // if (t == 16) cerr << "p = " << p << endl; if (p > (n>>t)) continue; p <<= t; long long v = n / p; for (int j=0; j<ts; j++) { long long x = tab[j]; while (i >= 0 && x * tab[i] > v) i--; if (i < 0) break; res = max(res, x * tab[i] * p); } } } cout << res << "\n"; return 0; } |