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