#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> using namespace std; vector <unsigned long long> dzielniki; int main() { ios_base::sync_with_stdio(0); cin.tie(0); unsigned long long n, m; cin >> n >> m; queue <pair <unsigned long long, unsigned long long> > liczby; if (m == 1) { cout << m; return 0; } unsigned long long wynik = 0; for(int i = 0; i < n; ++i) { unsigned long long a; cin >> a; dzielniki.push_back(a); liczby.push(make_pair(a, a)); wynik = max(wynik, a); } while (liczby.size()) { for (int i = 0; i < dzielniki.size(); ++i) { if (liczby.front().second <= dzielniki[i]) { if (liczby.front().first * dzielniki[i] <= m) { wynik = max(wynik, liczby.front().first * dzielniki[i]); if (wynik == m) { cout << m; return 0; } liczby.push(make_pair(liczby.front().first * dzielniki[i], dzielniki[i])); } } } liczby.pop(); } cout << wynik; 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 62 63 64 65 66 67 68 69 | #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> using namespace std; vector <unsigned long long> dzielniki; int main() { ios_base::sync_with_stdio(0); cin.tie(0); unsigned long long n, m; cin >> n >> m; queue <pair <unsigned long long, unsigned long long> > liczby; if (m == 1) { cout << m; return 0; } unsigned long long wynik = 0; for(int i = 0; i < n; ++i) { unsigned long long a; cin >> a; dzielniki.push_back(a); liczby.push(make_pair(a, a)); wynik = max(wynik, a); } while (liczby.size()) { for (int i = 0; i < dzielniki.size(); ++i) { if (liczby.front().second <= dzielniki[i]) { if (liczby.front().first * dzielniki[i] <= m) { wynik = max(wynik, liczby.front().first * dzielniki[i]); if (wynik == m) { cout << m; return 0; } liczby.push(make_pair(liczby.front().first * dzielniki[i], dzielniki[i])); } } } liczby.pop(); } cout << wynik; return 0; } |