#include <cstdio> #include <vector> typedef long long (*FastDivision)(long long); template<int n> long long FastDivisionImpl(long long value) { return value/n; } template<int n, int len=n> struct Division : Division<n-1, len> { Division<n, len>() { this->ops[n] = &FastDivisionImpl<n>; } }; template<int len> struct Division<0, len> { FastDivision ops[len+1]; long long operator() (long long a, int b) { return ops[b](a); } }; Division<100> div; std::vector<int> primes; long long answer = 1; void solve(long long N, int const *p, long long current_answer=1) { //printf(" solve(%lld, %d, %lld)\n", N, *p, current_answer); if (N * current_answer <= answer) return; if (*p == 0) return; if (current_answer > answer) answer = current_answer; if (N >= *p) solve(div(N, *p), p, current_answer * *p); solve(N, p+1, current_answer); } int main() { int k; long long N; scanf("%d %lld", &k, &N); primes.resize(k); for(auto &p : primes) scanf("%d", &p); primes.push_back(0); solve(N, primes.data()); printf("%lld\n", answer); }
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 | #include <cstdio> #include <vector> typedef long long (*FastDivision)(long long); template<int n> long long FastDivisionImpl(long long value) { return value/n; } template<int n, int len=n> struct Division : Division<n-1, len> { Division<n, len>() { this->ops[n] = &FastDivisionImpl<n>; } }; template<int len> struct Division<0, len> { FastDivision ops[len+1]; long long operator() (long long a, int b) { return ops[b](a); } }; Division<100> div; std::vector<int> primes; long long answer = 1; void solve(long long N, int const *p, long long current_answer=1) { //printf(" solve(%lld, %d, %lld)\n", N, *p, current_answer); if (N * current_answer <= answer) return; if (*p == 0) return; if (current_answer > answer) answer = current_answer; if (N >= *p) solve(div(N, *p), p, current_answer * *p); solve(N, p+1, current_answer); } int main() { int k; long long N; scanf("%d %lld", &k, &N); primes.resize(k); for(auto &p : primes) scanf("%d", &p); primes.push_back(0); solve(N, primes.data()); printf("%lld\n", answer); } |