#include <cstdio> #include <cstdint> #include <algorithm> #include <functional> using namespace std; #define KMAX 25 #define NMAX 1000000000000000000ULL #define PMAX 100 typedef unsigned long long ull; typedef uint8_t u8; u8 p[KMAX]; unsigned k; ull n, best = 1; void dfs(ull x, ull m) { if (x == 1) { best = max(best, m); return; } for (unsigned i = 0; i < k && p[i] <= x; ++i) { ull q = x/p[i], tm = m*p[i]; if (q*tm > best) { dfs(q, tm); } } } int main() { /*unsigned p[KMAX]; unsigned k; ull n;*/ scanf("%u%llu", &k, &n); for (unsigned i = 0; i < k; ++i) { scanf("%hhu", p+i); } sort(p, p+k, greater<u8>()); best = 1; dfs(n, 1); printf("%llu\n", best); 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 | #include <cstdio> #include <cstdint> #include <algorithm> #include <functional> using namespace std; #define KMAX 25 #define NMAX 1000000000000000000ULL #define PMAX 100 typedef unsigned long long ull; typedef uint8_t u8; u8 p[KMAX]; unsigned k; ull n, best = 1; void dfs(ull x, ull m) { if (x == 1) { best = max(best, m); return; } for (unsigned i = 0; i < k && p[i] <= x; ++i) { ull q = x/p[i], tm = m*p[i]; if (q*tm > best) { dfs(q, tm); } } } int main() { /*unsigned p[KMAX]; unsigned k; ull n;*/ scanf("%u%llu", &k, &n); for (unsigned i = 0; i < k; ++i) { scanf("%hhu", p+i); } sort(p, p+k, greater<u8>()); best = 1; dfs(n, 1); printf("%llu\n", best); return 0; } |