#include <cstdio> #include <vector> #include <algorithm> #define lld long long int #define GLIMIT 424242424 #define GLIMIT2 4294967295ll using namespace std; int k; lld n; int t[26]; unsigned poss[1930400]; int posCount = 0; lld maxRes = 0; lld left, right; void genAll(lld num, lld limit, int ind) { if (num > limit) return; if (ind == 0) { poss[posCount++] = num; return; } genAll(num * t[ind], limit, ind); genAll(num, limit, ind - 1); } void genMore(lld limit1, lld limit2) { for (int i = 1; i <= k; i++) { lld num = 1; while (num <= limit2) { if (num > limit1) { poss[posCount++] = (unsigned)num; } num = num * t[i]; } } for (int i = 1; i <= k; i++) for (int j = i + 1; j <= k; j++) { lld num = 1; while (num <= limit2) { lld num2 = num; while (num2 <= limit2) { if (num2 > limit1) { poss[posCount++] = (unsigned)num2; } num2 = num2 * t[j]; } num = num * t[i]; } } } int indL; lld countt = 0; void countAll(lld num, lld limit, int ind) { if (num > limit) return; if (ind == 0) { if (n / num > GLIMIT2) { indL = posCount; } else { countt++; indL = upper_bound(poss, poss + posCount, n / num) - poss; } if (num * poss[indL - 1] > maxRes) { maxRes = num * poss[indL - 1]; left = poss[indL - 1]; right = num; } return; } countAll(num * t[ind], limit, ind); countAll(num, limit, ind - 1); } int main() { scanf("%d%lld", &k, &n); for (int i = 1; i <= k; i++) { scanf("%d", &t[i]); } sort(t + 1, t + k + 1); genAll(1, GLIMIT, k); genMore(GLIMIT, GLIMIT2); sort(poss, poss + posCount); lld limit; if (n > 100000000000000000ll) limit = (n / GLIMIT) * 20; else if (n > 10000000000000000ll) limit = (n / GLIMIT) * 35; else limit = ((n * 60) / GLIMIT); if (limit == 0) limit = 1; countAll(1, limit, k); printf("%lld\n", maxRes); 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 98 99 100 101 102 103 104 105 | #include <cstdio> #include <vector> #include <algorithm> #define lld long long int #define GLIMIT 424242424 #define GLIMIT2 4294967295ll using namespace std; int k; lld n; int t[26]; unsigned poss[1930400]; int posCount = 0; lld maxRes = 0; lld left, right; void genAll(lld num, lld limit, int ind) { if (num > limit) return; if (ind == 0) { poss[posCount++] = num; return; } genAll(num * t[ind], limit, ind); genAll(num, limit, ind - 1); } void genMore(lld limit1, lld limit2) { for (int i = 1; i <= k; i++) { lld num = 1; while (num <= limit2) { if (num > limit1) { poss[posCount++] = (unsigned)num; } num = num * t[i]; } } for (int i = 1; i <= k; i++) for (int j = i + 1; j <= k; j++) { lld num = 1; while (num <= limit2) { lld num2 = num; while (num2 <= limit2) { if (num2 > limit1) { poss[posCount++] = (unsigned)num2; } num2 = num2 * t[j]; } num = num * t[i]; } } } int indL; lld countt = 0; void countAll(lld num, lld limit, int ind) { if (num > limit) return; if (ind == 0) { if (n / num > GLIMIT2) { indL = posCount; } else { countt++; indL = upper_bound(poss, poss + posCount, n / num) - poss; } if (num * poss[indL - 1] > maxRes) { maxRes = num * poss[indL - 1]; left = poss[indL - 1]; right = num; } return; } countAll(num * t[ind], limit, ind); countAll(num, limit, ind - 1); } int main() { scanf("%d%lld", &k, &n); for (int i = 1; i <= k; i++) { scanf("%d", &t[i]); } sort(t + 1, t + k + 1); genAll(1, GLIMIT, k); genMore(GLIMIT, GLIMIT2); sort(poss, poss + posCount); lld limit; if (n > 100000000000000000ll) limit = (n / GLIMIT) * 20; else if (n > 10000000000000000ll) limit = (n / GLIMIT) * 35; else limit = ((n * 60) / GLIMIT); if (limit == 0) limit = 1; countAll(1, limit, k); printf("%lld\n", maxRes); return 0; } |