#include <iostream> using namespace std; long long n, k; int tab[100]; long long p[30]; int M = 0; long long result = 1; long long pp[30][70]; void f(int i, long long current){ if(i<M){ int j = 0; while(pp[i][j] * current <=n){ // cout << p[i] << " " << pp[i][j] << " " << j << endl; f(i + 1, pp[i][j] * current); j++; } } if(result < current){ result = current; } } int main(){ cin >> k >> n; for(int tmp,i = 0; i < k; i++){ cin >> tmp; tab[tmp] = 1; } for(int i = 100; i > 1; i--){ if(tab[i]){ p[M++]=i; } } for(long long i=0;i<M;i++){ pp[i][0] = 1; for(long long j=1;j<200;j++){ pp[i][j] = p[i] * pp[i][j-1]; } } f(0, 1); cout << result << 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 39 40 41 42 43 44 45 46 47 48 | #include <iostream> using namespace std; long long n, k; int tab[100]; long long p[30]; int M = 0; long long result = 1; long long pp[30][70]; void f(int i, long long current){ if(i<M){ int j = 0; while(pp[i][j] * current <=n){ // cout << p[i] << " " << pp[i][j] << " " << j << endl; f(i + 1, pp[i][j] * current); j++; } } if(result < current){ result = current; } } int main(){ cin >> k >> n; for(int tmp,i = 0; i < k; i++){ cin >> tmp; tab[tmp] = 1; } for(int i = 100; i > 1; i--){ if(tab[i]){ p[M++]=i; } } for(long long i=0;i<M;i++){ pp[i][0] = 1; for(long long j=1;j<200;j++){ pp[i][j] = p[i] * pp[i][j-1]; } } f(0, 1); cout << result << endl; return 0; } |