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

Re:小日本的题很多都是水淋淋的啊!

Posted by qylsw at 2010-07-17 16:28:05 on Problem 3518
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:
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