#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> p; ll maks = 0; void oblicz(short ind, ll ilo, ll &k, ll &n){ if(ind == k){ maks = max(maks, ilo); return; } for(int i = 1; i*ilo <= n; i *= p[ind]) oblicz(ind + 1, ilo*i, k, n); } int main(){ ios_base::sync_with_stdio(0); ll k, n, a; cin >> k >> n; for(int i = 0; i < k; i++){ cin >> a; p.push_back(a); } oblicz(0, 1, k, n); cout << maks; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> p; ll maks = 0; void oblicz(short ind, ll ilo, ll &k, ll &n){ if(ind == k){ maks = max(maks, ilo); return; } for(int i = 1; i*ilo <= n; i *= p[ind]) oblicz(ind + 1, ilo*i, k, n); } int main(){ ios_base::sync_with_stdio(0); ll k, n, a; cin >> k >> n; for(int i = 0; i < k; i++){ cin >> a; p.push_back(a); } oblicz(0, 1, k, n); cout << maks; } |