#include <cstdio> #include <algorithm> using namespace std; #define LL long long LL primes[32]; LL find_closest(LL* p, LL p_cnt, LL n, LL* powers) { LL limit = 1LL << p_cnt; for (LL i=0; i < limit; i++) { for (int j=0; j < p_cnt; j++) { if (i & (1LL << j)) { } } } return 0; } LL go(LL level, LL current_value, LL max_level, LL max_value) { if (level == max_level) { return current_value; } LL prime = primes[level]; LL best_result = current_value; best_result = max(best_result, go(level+1, current_value, max_level, max_value)); while (current_value * prime <= max_value) { current_value *= prime; best_result = max(best_result, current_value); best_result = max(best_result, go(level + 1, current_value, max_level, max_value)); } return best_result; } int main() { LL n, k; scanf("%lld%lld", &k, &n); for (int i=0; i < k; i++) { scanf("%lld", &primes[i]); } printf("%lld\n", go(0, 1, k, 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 | #include <cstdio> #include <algorithm> using namespace std; #define LL long long LL primes[32]; LL find_closest(LL* p, LL p_cnt, LL n, LL* powers) { LL limit = 1LL << p_cnt; for (LL i=0; i < limit; i++) { for (int j=0; j < p_cnt; j++) { if (i & (1LL << j)) { } } } return 0; } LL go(LL level, LL current_value, LL max_level, LL max_value) { if (level == max_level) { return current_value; } LL prime = primes[level]; LL best_result = current_value; best_result = max(best_result, go(level+1, current_value, max_level, max_value)); while (current_value * prime <= max_value) { current_value *= prime; best_result = max(best_result, current_value); best_result = max(best_result, go(level + 1, current_value, max_level, max_value)); } return best_result; } int main() { LL n, k; scanf("%lld%lld", &k, &n); for (int i=0; i < k; i++) { scanf("%lld", &primes[i]); } printf("%lld\n", go(0, 1, k, n)); return 0; } |