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<stdio.h> #define num 100000 int z[num]= {2,3}; void db(void) { int i,j,k=2,flag; for(i=5; i<num; i+=2) { flag=1; for(j=0; z[j]*z[j]<=i; j++) { if(i%z[j]==0) { flag=0; break; } } if(flag==1)z[k++]=i; } } int main() { //freopen("haha.txt","r",stdin); db(); int m,a,b,i,j,k,max,p1,p2,s; float c1,c2; //for(i=0;i<100;i++)printf("%d ",z[i]); while(scanf("%d%d%d",&m,&a,&b)) { if(m==0&&a==0&&b==0)break; c1=(float)a/(float)b; max=0; for(i=0; z[i]*z[i]<=m; i++) for(j=i; z[i]*z[j]<=m; j++) { c2=(float)z[i]/(float)z[j]; if(c1<=c2) //a/b <= p/q <= 1 { s=z[i]*z[j]; if(s>max) { max=s; p1=z[i]; p2=z[j]; } } } printf("%d %d\n",p1,p2); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator