POJ 1411
1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #define MAXN 50000 5 using namespace std; 6 7 void give_list(); 8 double prime[5200] = {0}; 9 int num = 5200; 10 int main() 11 { 12 //freopen("acm.acm","r",stdin); 13 int i; 14 int j; 15 double m; 16 double a; 17 double b; 18 give_list(); 19 i = 0; 20 j = 0; 21 int x; 22 int y; 23 int k; 24 int tem; 25 int max = 0; 26 while(cin>>m>>a>>b) 27 { 28 if(!m) 29 break; 30 max = 0; 31 while(prime[i]*prime[i] <= m) ++ i; 32 -- i; 33 k = i; 34 for(; i >= 0; -- i) 35 { 36 for(j = k; j < num; ++ j) 37 { 38 tem = prime[i]*prime[j]; 39 if(tem > m||prime[i]/prime[j] < a/b) 40 break; 41 if(tem > max) 42 { 43 max = tem; 44 x = prime[i]; 45 y = prime[j]; 46 } 47 } 48 } 49 cout<<x<<" "<<y<<endl; 50 } 51 } 52 void give_list() 53 { 54 int i; 55 int j; 56 bool prim1[MAXN]; 57 memset(prim1,true,sizeof(bool)*MAXN); 58 prim1[1] = false; 59 for(i = 2; i < sqrt(long double(MAXN))+1; i ++) 60 { 61 if(prim1[i]) 62 { 63 j = 2*i; 64 while(j < MAXN) 65 { 66 prim1[j] = false; 67 j += i; 68 } 69 } 70 } 71 j = 0; 72 for(i = 2; i < MAXN; i ++) 73 { 74 if(prim1[i]) 75 { 76 prime[j] = i; 77 ++ j; 78 } 79 } 80 }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com