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:小日本的题很多都是水淋淋的啊!In Reply To:小日本的题很多都是水淋淋的啊! Posted by:mightyvoice at 2009-04-15 20:08:20 是的 #include<iostream> #include<math.h> using namespace std; int f(int x){ int j,k=sqrt(double(x)); for(j=2;j<=k;j++) if(x%j==0) break; if(j>=k+1) return 1; else return 0; } int main() { int x; while(scanf("%d",&x)&&x!=0){ int i,c=0; for(i=0;;i--) if(f(x+i)==1) break; c=c-i; for(i=0;;i++) if(f(x+i)==1) break; c=c+i; printf("%d\n",c); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator