#include <iostream> #include <string> #include <set> using namespace std; set<long long> q; set<long long>::iterator it; int main() { int K; cin >> K; long long N; cin >> N; long long P[K]; for (int i = 0; i < K; i++) { cin >> P[i]; q.insert(P[i]); } long long ANS = 1LL; while (q.size() > 0) { it = q.begin(); long long num = *it; q.erase(it); ANS =max (ANS, num); for (int i=0; i<K; i++){ long long newNum = num * P[i]; if (newNum <= N && q.count(newNum)==0){ q.insert(newNum); } } } cout << ANS << 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 | #include <iostream> #include <string> #include <set> using namespace std; set<long long> q; set<long long>::iterator it; int main() { int K; cin >> K; long long N; cin >> N; long long P[K]; for (int i = 0; i < K; i++) { cin >> P[i]; q.insert(P[i]); } long long ANS = 1LL; while (q.size() > 0) { it = q.begin(); long long num = *it; q.erase(it); ANS =max (ANS, num); for (int i=0; i<K; i++){ long long newNum = num * P[i]; if (newNum <= N && q.count(newNum)==0){ q.insert(newNum); } } } cout << ANS << endl; return 0; } |