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

I just can't find out that why i got wa...

Posted by sehdan at 2008-11-11 15:48:44 on Problem 3518
here is my code...
I need your help...

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAX 1300000
void prime(int pr[MAX])
{
	int prim[MAX];
	int pnum(0);
    memset(pr,0,sizeof(pr));
    for (int i=2;i<MAX;i++)
    {
        if (!pr[i])     prim[pnum++]=i;
        for (int j=0; j<pnum && prim[j]*i<MAX ; j++)
        {
            pr[prim[j]*i] = 1;
            if (i%prim[j]==0) break;
        }
    }
}
int main()
{
	int pr[MAX];
	prime(pr);
	int n;
	int s,e;
	while(1)
	{
		scanf("%d",&n);
		if(n)
		{
			if(pr[n])
			{
				s = e = n;
				while(pr[--s]);
				while(pr[++e]);
				printf("%d\n",e-s);
			}
			else
				printf("0\n");
		}
		else
			break;
	}
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