Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
昨天同样的算法,今天重写一下就过了#include<iostream> #include<math.h> using namespace std; bool IsPrime(int n) { int m = sqrt(n*1.0); for(int i=2;i<=m;i++) { if(n%i==0) return false; } return true; } int main() { int m,a,b; while(cin>>m>>a>>b) { if(m+a+b==0) break; int bounds = sqrt(m*1.0); int max = 0; int p,q; for(int i=2;i<=bounds;i++) { if(!IsPrime(i)) continue; int e = (i*b)/a; int min = m/i; if(e>min) e = min; for(int j=e;j>=i;j--) { if(IsPrime(j)) { if(i*j>max) { max = i*j; p=i; q=j; } break; } } } cout<<p<<" "<<q<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator