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:wa??

Posted by hdjtdxacm at 2009-02-19 16:22:14 on Problem 3518
In Reply To:wa?? Posted by:hdjtdxacm at 2009-02-19 15:55:11
> #include<stdio.h>
> //用筛选法求素数 
> bool p[1299720];
> int main()
> {
> 	int k,ans,i,i2;
> for(i=0;i<=1299709;i+=2){ p[i]=0; } 
> for(i=1;i<=1299709;i+=2){ p[i]=1; } 
> p[2]=1;p[1]=0;
> for(i=3;i<=1000;i+=2)
> { if(p[i]==1)
> {i2=i+i; k=i2+i;
> while(k<=1299709)
> {p[k]=0;k+=i2;}
> }
> }
> 	while(scanf("%d",&k)&&k!=0)
> 	{
> 		if(k==1)
> 		{
> 			printf("0\n");
> 			continue;
> 		}
> 		if(p[k]==1)
> 		{
> 			printf("0\n");
> 			continue;
> 		}
> 		else
> 		{
> 			ans=1;
> 			for(i=k-1;;i--)
> 			{
> 				if(p[i]==0)
> 					ans++;
> 				else
> 					break;
> 			}
> 			for(i=k+1;;i++)
> 			{
> 				if(p[i]==0)
> 					ans++;
> 				else
> 					break;
> 			}
> 			printf("%d\n",ans+1);
> 		}
> 	}
> 	return 0;
> }/*10
> 11
> 27
> 2
> 492170
> 0*/
哦,原来是这里 for(i=3;i<=1000;i+=2)i<10000;终于ac了

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