Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

sos:运行结果正确 (wa)

Posted by chmx at 2008-04-26 19:20:25 on Problem 3518
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator