#include <bits/stdc++.h> using namespace std; long long inf = 1e18; long long inf2 = 1e10; long long wynik = 1; long long n; long long minval = 0; void generuj(vector <int> const &A, vector <long long> const &W, int i, long long ilo) { if(ilo > n) return; if(i == (int) A.size()) { if(ilo < minval) return; int wy = -1; int p = 0; int k = (int) W.size() - 1; long long war = n / ilo; while(p <= k) { int s = (p + k) / 2; if(W[s] <= war) { wy = s; p = s + 1; } else k = s - 1; } if(wy >= 0) wynik = max(wynik, ilo * W[wy]); return; } if(ilo <= inf / A[i]) generuj(A, W, i, ilo * A[i]); generuj(A, W, i + 1, ilo); } void cisnij(vector <int> A, vector <int> B) { vector <long long> W; W.push_back(1); for(auto u : B) { for(int i = 0; i < (int) W.size(); ++i) if(W[i] <= inf2 / u) W.push_back(W[i] * u); } sort(W.begin(), W.end()); sort(A.begin(), A.end(), greater <int> ()); generuj(A, W, 0, 1); } int main() { int k; cin >> k >> n; double pom = sqrt((double) n); pom /= 10.0; pom -= 10; minval = max(0LL, (long long) pom); vector <int> p1, p2; for(int i = 1; i <= k; ++i) { int a; cin >> a; if(a <= 19) p1.push_back(a); else p2.push_back(a); } cisnij(p1, p2); if(wynik != n) cisnij(p2, p1); cout << wynik << endl; 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 | #include <bits/stdc++.h> using namespace std; long long inf = 1e18; long long inf2 = 1e10; long long wynik = 1; long long n; long long minval = 0; void generuj(vector <int> const &A, vector <long long> const &W, int i, long long ilo) { if(ilo > n) return; if(i == (int) A.size()) { if(ilo < minval) return; int wy = -1; int p = 0; int k = (int) W.size() - 1; long long war = n / ilo; while(p <= k) { int s = (p + k) / 2; if(W[s] <= war) { wy = s; p = s + 1; } else k = s - 1; } if(wy >= 0) wynik = max(wynik, ilo * W[wy]); return; } if(ilo <= inf / A[i]) generuj(A, W, i, ilo * A[i]); generuj(A, W, i + 1, ilo); } void cisnij(vector <int> A, vector <int> B) { vector <long long> W; W.push_back(1); for(auto u : B) { for(int i = 0; i < (int) W.size(); ++i) if(W[i] <= inf2 / u) W.push_back(W[i] * u); } sort(W.begin(), W.end()); sort(A.begin(), A.end(), greater <int> ()); generuj(A, W, 0, 1); } int main() { int k; cin >> k >> n; double pom = sqrt((double) n); pom /= 10.0; pom -= 10; minval = max(0LL, (long long) pom); vector <int> p1, p2; for(int i = 1; i <= k; ++i) { int a; cin >> a; if(a <= 19) p1.push_back(a); else p2.push_back(a); } cisnij(p1, p2); if(wynik != n) cisnij(p2, p1); cout << wynik << endl; return 0; } |