Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11211 | Accepted: 4356 |
Description
Input
Output
Sample Input
5 1 2 99999 999 999 1680 5 16 1970 1 1 2002 4 11 0 0 0
Sample Output
2 2 313 313 23 73 43 43 37 53
Source
#include<cstdio> #include<cmath> #include<iostream> using namespace std; #define N 100001 int prime[N]; bool check[N]; int n,a,b,m,tot; int main(){ for(int i=2;i<=N;i++) if(!check[i]){ prime[n++]=i; for(int j=i*2;j<=N;j+=i) check[j]=1; } while(scanf("%d %d %d",&m,&a,&b)==3&&m&&a&&b){ double adivb=a*1.0/b,tmp=0; int ansi,ansj; for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ double t1=1.0*prime[i]*prime[j]; double t2=1.0*prime[i]/prime[j]; if(t1>tmp&&t1<=m&&t2>=adivb&&t2<=1){ tmp=t1;ansi=i;ansj=j; } } } printf("%d %d\n",prime[ansi],prime[ansj]); } return 0; }
poj 1141 Calling Extraterrestrial Intelligence Again(超时)
原文:http://www.cnblogs.com/shenben/p/5536074.html