#include <stdio.h> #include <limits.h> #include <vector> using namespace std; #define FOR0(i, n) for (int i = 0; i < n; i++) int k; unsigned long long n, maxx; vector<unsigned long long> P; void pre() { FOR0(i, k) { unsigned long long tmp = P[i]; unsigned long long v = ULLONG_MAX / P[i]; if (P[i] <= n) while (tmp <= n && tmp <= v) tmp *= P[i]; if (tmp <= v) tmp /= P[i]; if (maxx < tmp) maxx = tmp; } } void in(unsigned long long p_act, unsigned long long p_val) { int mod; unsigned long long act = p_act, val = p_val; FOR0(i, k) { mod = act % P[i]; act -= mod; if (act * val <= maxx) { if (maxx < val) maxx = val; } else { act /= P[i]; val *= P[i]; if (act == 1) { if (maxx < val) maxx = val; } else in(act, val); } act = p_act; val = p_val; } } int main() { scanf("%d%llu", &k, &n); int tmp; FOR0(i, k) { scanf("%d", &tmp); P.push_back(tmp); } pre(); if (maxx != n) in(n, 1); printf("%llu\n", maxx); 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 | #include <stdio.h> #include <limits.h> #include <vector> using namespace std; #define FOR0(i, n) for (int i = 0; i < n; i++) int k; unsigned long long n, maxx; vector<unsigned long long> P; void pre() { FOR0(i, k) { unsigned long long tmp = P[i]; unsigned long long v = ULLONG_MAX / P[i]; if (P[i] <= n) while (tmp <= n && tmp <= v) tmp *= P[i]; if (tmp <= v) tmp /= P[i]; if (maxx < tmp) maxx = tmp; } } void in(unsigned long long p_act, unsigned long long p_val) { int mod; unsigned long long act = p_act, val = p_val; FOR0(i, k) { mod = act % P[i]; act -= mod; if (act * val <= maxx) { if (maxx < val) maxx = val; } else { act /= P[i]; val *= P[i]; if (act == 1) { if (maxx < val) maxx = val; } else in(act, val); } act = p_act; val = p_val; } } int main() { scanf("%d%llu", &k, &n); int tmp; FOR0(i, k) { scanf("%d", &tmp); P.push_back(tmp); } pre(); if (maxx != n) in(n, 1); printf("%llu\n", maxx); return 0; } |