#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; static ll maxValue; static ll bestValue; static ll llMaxValue = numeric_limits<ll>::max(); void solution(ll value, vector<int>::iterator it, vector<int>::iterator end) { if (value > bestValue) { bestValue = value; } while(it != end) { if ((llMaxValue / (*it)) < value) return; ll tempV = value * (*it); if (tempV > maxValue) return; solution(tempV, it, end); ++it; } } int main() { ios::sync_with_stdio(0); maxValue = 372399299269961ULL; bestValue = 1; vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; int primesQ = 0; cin >> primesQ >> maxValue; primes.resize(primesQ); for (auto& v: primes) cin >> v; sort(primes.begin(), primes.end()); solution(1, primes.begin(), primes.end()); printf("%llu\n", bestValue); 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 | #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; static ll maxValue; static ll bestValue; static ll llMaxValue = numeric_limits<ll>::max(); void solution(ll value, vector<int>::iterator it, vector<int>::iterator end) { if (value > bestValue) { bestValue = value; } while(it != end) { if ((llMaxValue / (*it)) < value) return; ll tempV = value * (*it); if (tempV > maxValue) return; solution(tempV, it, end); ++it; } } int main() { ios::sync_with_stdio(0); maxValue = 372399299269961ULL; bestValue = 1; vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; int primesQ = 0; cin >> primesQ >> maxValue; primes.resize(primesQ); for (auto& v: primes) cin >> v; sort(primes.begin(), primes.end()); solution(1, primes.begin(), primes.end()); printf("%llu\n", bestValue); return 0; } |