#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef pair < int, int > PII; typedef pair < LL, LL > PLL; typedef pair < LD, LD > PDD; #define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define MP make_pair template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } #ifdef LOCAL #define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__) #else #define DBG(...) (__VA_ARGS__) #define cerr if(0) cout #endif // ********************** CODE ********************** // const int N = 30; int k; LL n, p[N], ans = 1; vector < int > v; inline void upd(LL can) { LL id = upper_bound(all(v), n / can) - v.begin() - 1; if(id > -1) { ans = max(ans, can * LL(v[id])); } } LL prog1, prog2; void Go2(int i, LL akt = 1) { if(akt > prog1) return; if(LD(akt) >= LD(n) / LD(prog2)) { upd(akt); return; } if(i == k) { ans = max(ans, akt); return; } LL pot = 1; Go2(i + 1, akt); while(akt * pot * p[i] <= prog1) { pot *= p[i]; Go2(i + 1, akt * pot); } } void Go(int i, LL akt = 1, bool byl = 0) { if(akt > prog2) return; if(!byl) v.push_back(akt); if(i == k) return; LL pot = 1; Go(i + 1, akt, 1); while(LL(akt) * pot * p[i] <= prog2) { pot *= p[i]; Go(i + 1, akt * pot, 0); } } int main() { _upgrade cin >> k >> n; for(int i = 0; i < k; i++) cin >> p[i]; sort(p, p + k), reverse(p, p + k); prog1 = min(n, LL(10e10)); prog2 = min(n, LL(1e8)); Go(0); sort(all(v)); v.erase(unique(all(v)), v.end()); ans = v.back(); Go2(0); cout << ans << "\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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef pair < int, int > PII; typedef pair < LL, LL > PLL; typedef pair < LD, LD > PDD; #define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define MP make_pair template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } #ifdef LOCAL #define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__) #else #define DBG(...) (__VA_ARGS__) #define cerr if(0) cout #endif // ********************** CODE ********************** // const int N = 30; int k; LL n, p[N], ans = 1; vector < int > v; inline void upd(LL can) { LL id = upper_bound(all(v), n / can) - v.begin() - 1; if(id > -1) { ans = max(ans, can * LL(v[id])); } } LL prog1, prog2; void Go2(int i, LL akt = 1) { if(akt > prog1) return; if(LD(akt) >= LD(n) / LD(prog2)) { upd(akt); return; } if(i == k) { ans = max(ans, akt); return; } LL pot = 1; Go2(i + 1, akt); while(akt * pot * p[i] <= prog1) { pot *= p[i]; Go2(i + 1, akt * pot); } } void Go(int i, LL akt = 1, bool byl = 0) { if(akt > prog2) return; if(!byl) v.push_back(akt); if(i == k) return; LL pot = 1; Go(i + 1, akt, 1); while(LL(akt) * pot * p[i] <= prog2) { pot *= p[i]; Go(i + 1, akt * pot, 0); } } int main() { _upgrade cin >> k >> n; for(int i = 0; i < k; i++) cin >> p[i]; sort(p, p + k), reverse(p, p + k); prog1 = min(n, LL(10e10)); prog2 = min(n, LL(1e8)); Go(0); sort(all(v)); v.erase(unique(all(v)), v.end()); ans = v.back(); Go2(0); cout << ans << "\n"; return 0; } |