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> #include <math.h> int main() { int a[2000]; int tp,num=0,m,c,b,p,q,n,i,j; double s; for (i=2;i<9091;i++) { tp=0; for (j=2;j<=(int)sqrt(i);j++) if (i%j==0) {tp=1;break;} if (tp==0) { a[num]=i; num++; } } while(EOF!=scanf("%d%d%d",&m,&c,&b)) { while (m>0) { n=0; s=(double)c/b; for (i=num-1;i>=0;i--) { if (a[i]>m) continue; for (j=i;j<=num-1;j++) { if (a[j]>m||a[j]*a[i]>m||((double)a[i]/a[j])<s) break; if (a[j]*a[i]>n) { n=a[i]*a[j]; p=a[i]; q=a[j]; } } } printf("%d %d\n",p,q); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator