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 |
Re:唉,谁能告诉我为什么wa了??快吐血了~~~In Reply To:唉,谁能告诉我为什么wa了??快吐血了~~~ Posted by:chqch172443 at 2008-07-01 16:01:37 > 测试数据都对,连最大那个质数都对,为什么就是wa了?? > > #include<stdio.h> > #include<math.h> > int prime(n) > {int k,i; > if(n>10000) k=(int)(sqrt(n/10000)*100); > else k=(int)sqrt(n); > for(i=2;i<=k;i++) > if(n%i==0) break; > if(i>k) return 1; > else return 0; > } > void main() > {int n,t,s; > while(scanf("%d",&n)) > {if(n==0) break; > if(prime(n)) printf("0\n"); > else > {for(t=n-1;;t--) > if(prime(t)) break; > for(s=n+1;;s++) > if(prime(s)) break; > printf("%d\n",s-t); > } > } > } 边缘数据,、n = 1,print 0 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator