HDU Calling Extraterrestrial Intelligence Again
如图,下面代码
#include <iostream> #include <cstring> using namespace std; const int N=10005; int p,q,prime[N],ans[N],num=0; int primePrint(){ int i,j; memset(prime,0,sizeof(prime)); for(i=2;i<=N;i++){ if(prime[i]) continue; for(j=i+i;j<=N;j+=i){ prime[j]=1; } ans[num++]=i; } } int main(){ int m,ansp,ansq; double a,b,Min,Max; primePrint(); while(cin>>m>>a>>b){ if(m==0&&a==0&&b==0) break; Max=0; Min=a/b; for(p=num-1;p>=0;p--){ for(q=p;q>=0;q--){ if(ans[p]*ans[q]>m||(double)ans[q]/ans[p]<Min) continue; if(ans[p]*ans[q]>Max){ Max=ans[p]*ans[q]; ansp=ans[p]; ansq=ans[q]; } } } cout<<ansq<<" "<<ansp<<endl; } return 0; }