#include <iostream> #include <algorithm> #include <vector> #include <set> using namespace std; int main() { unsigned long long k, n; cin >> k >> n; vector<unsigned long long> A; vector<unsigned int> primes; while(k--) { int p; cin >> p; primes.push_back(p); } A.push_back(1); bool inserted_something; unsigned long long current_max = 0; while(!A.empty()) { inserted_something = false; vector<unsigned long long> B; for(unsigned long long x : A) { for(unsigned long long p: primes) { auto new_val = x * p; if (new_val <= n) { current_max = max(new_val, current_max); B.push_back(new_val); } } } A = B; }; cout << current_max << endl; 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 | #include <iostream> #include <algorithm> #include <vector> #include <set> using namespace std; int main() { unsigned long long k, n; cin >> k >> n; vector<unsigned long long> A; vector<unsigned int> primes; while(k--) { int p; cin >> p; primes.push_back(p); } A.push_back(1); bool inserted_something; unsigned long long current_max = 0; while(!A.empty()) { inserted_something = false; vector<unsigned long long> B; for(unsigned long long x : A) { for(unsigned long long p: primes) { auto new_val = x * p; if (new_val <= n) { current_max = max(new_val, current_max); B.push_back(new_val); } } } A = B; }; cout << current_max << endl; return 0; } |