#include <stdio.h> #include <algorithm> #include <math.h> #include <vector> #include <cstring> using namespace std; const int N=600000; vector<int>A,B; int x[110],n,len,pd[110],pre[600100]; long long lim,y[60000],ans,sqrlim,limA[100],limB[100]; void dfs(int k1,long long k2){ //cout<<"asd "<<k1<<" "<<k2<<endl; if (k1>=A.size()){ if (k2<=N) pre[k2]=k2; else y[++len]=k2; return; } dfs(k1+1,k2); while (k2<=limA[k1]){ k2*=A[k1]; dfs(k1+1,k2); } } int tot=0; void dfs2(int k1,long long k2){ if (k1>=B.size()){ long long limnow=lim/k2; if (limnow<=N) ans=max(ans,pre[limnow]*k2); else if (limnow<y[1]) ans=max(ans,pre[N]*k2); else { int where=upper_bound(y+1,y+len+1,limnow)-y-1; //tot++; ans=max(ans,y[where]*k2); } return; } dfs2(k1+1,k2); while (k2<=limB[k1]){ k2*=B[k1]; dfs2(k1+1,k2); } } void solve(){ memset(pre,0x00,sizeof pre); for (int i=0;i<A.size();i++) limA[i]=sqrlim/A[i]; for (int i=0;i<B.size();i++) limB[i]=lim/B[i]; len=0; tot=0; dfs(0,1); sort(y+1,y+len+1); y[len+1]=lim+1; for (int i=1;i<=N;i++) pre[i]=max(pre[i-1],pre[i]); dfs2(0,1); //cout<<len<<" "<<tot<<endl; } int main(){ scanf("%d%lld",&n,&lim); for (int i=1;i<=n;i++) scanf("%d",&x[i]); sqrlim=sqrt(lim); sqrlim=max(sqrlim,0ll); while (sqrlim*sqrlim<=lim) sqrlim++; while (sqrlim*sqrlim>lim) sqrlim--; sort(x+1,x+n+1); n=unique(x+1,x+n+1)-x-1; for (int i=1;i<=n;i++) if (i/2%2==0) A.push_back(x[i]); else B.push_back(x[i]); ans=0; solve(); swap(A,B); solve(); printf("%lld\n",ans); 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 | #include <stdio.h> #include <algorithm> #include <math.h> #include <vector> #include <cstring> using namespace std; const int N=600000; vector<int>A,B; int x[110],n,len,pd[110],pre[600100]; long long lim,y[60000],ans,sqrlim,limA[100],limB[100]; void dfs(int k1,long long k2){ //cout<<"asd "<<k1<<" "<<k2<<endl; if (k1>=A.size()){ if (k2<=N) pre[k2]=k2; else y[++len]=k2; return; } dfs(k1+1,k2); while (k2<=limA[k1]){ k2*=A[k1]; dfs(k1+1,k2); } } int tot=0; void dfs2(int k1,long long k2){ if (k1>=B.size()){ long long limnow=lim/k2; if (limnow<=N) ans=max(ans,pre[limnow]*k2); else if (limnow<y[1]) ans=max(ans,pre[N]*k2); else { int where=upper_bound(y+1,y+len+1,limnow)-y-1; //tot++; ans=max(ans,y[where]*k2); } return; } dfs2(k1+1,k2); while (k2<=limB[k1]){ k2*=B[k1]; dfs2(k1+1,k2); } } void solve(){ memset(pre,0x00,sizeof pre); for (int i=0;i<A.size();i++) limA[i]=sqrlim/A[i]; for (int i=0;i<B.size();i++) limB[i]=lim/B[i]; len=0; tot=0; dfs(0,1); sort(y+1,y+len+1); y[len+1]=lim+1; for (int i=1;i<=N;i++) pre[i]=max(pre[i-1],pre[i]); dfs2(0,1); //cout<<len<<" "<<tot<<endl; } int main(){ scanf("%d%lld",&n,&lim); for (int i=1;i<=n;i++) scanf("%d",&x[i]); sqrlim=sqrt(lim); sqrlim=max(sqrlim,0ll); while (sqrlim*sqrlim<=lim) sqrlim++; while (sqrlim*sqrlim>lim) sqrlim--; sort(x+1,x+n+1); n=unique(x+1,x+n+1)-x-1; for (int i=1;i<=n;i++) if (i/2%2==0) A.push_back(x[i]); else B.push_back(x[i]); ans=0; solve(); swap(A,B); solve(); printf("%lld\n",ans); return 0; } |