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 |
sos:运行结果正确 (wa)#include<iostream> #include<cmath> using namespace std; int fun(int n) //whether n is prime { int i,j=1; for(i=2;i<=sqrt(n);i++) if(n%i==0) j=0; return j; } int main() { int n; int t,s; while(cin>>n) { if(fun(n))//if is prime output 0 cout<<0<<endl; else { for(t=n-1;;t--) if(fun(t)) break; for(s=n+1;;s++) if(fun(s)) break; cout<<s-t<<endl; } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator