| ||||||||||
| 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 | |||||||||
I just can't find out that why i got wa...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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator