| ||||||||||
| 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 | |||||||||
为什么总是Runtime Error 能解释吗?#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
const int maxn=1000010;
__int64 Primelist[100000];
int Primenum;
int IsNotPrime[1000010];
void SegmentPrime(__int64 L,__int64 U)
{
__int64 i,j,SU,d;
SU=(int)sqrt(1.0*U);
d=U-L+1;
memset(Primelist,0,sizeof(Primelist));
for(i=0;i<d;i++)
{
IsNotPrime[i]=0;
}
for(i=(L%2!=0);i<d;i+=2)
{
IsNotPrime[i]=1;
}
for(i=3;i<=SU;i+=2)
{
if(i>L&&IsNotPrime[i-L])
{
continue;
}
j=(L/i)*i;
if(j<i)
{
j+=i;
}
if(j==i)
{
j+=i;
}
for(j-=L;j<d;j+=i)
{
IsNotPrime[j]=1;
}
}
if(L<=1)
{
IsNotPrime[1-L]=1;
}
if(L<=2)
{
IsNotPrime[2-L]=0;
}
Primenum=0;
for(i=0;i<d;i++)
{
if(!IsNotPrime[i])
{
Primelist[Primenum++]=i+L;
}
}
}
int main()
{
__int64 n,m;
int flag;
__int64 i,a,b,x,y,min,max,temp,t;
while(scanf("%I64d%I64d",&n,&m)!=EOF)
{
SegmentPrime(n,m);
x=y=0;
a=b=0;
flag=0;
max=0;
temp=0;
for(i=0;i<maxn;i++)
{
if(!Primelist[i]) break;
if(!a) a=Primelist[i];
else if(!b)
{
b=Primelist[i];
t=b;
min=b-a;
flag++;
}
else
{
if(Primelist[i]-t<min)
{
min=Primelist[i]-t;
a=t;
b=Primelist[i];
t=Primelist[i];
}
else
{
t=Primelist[i];
}
}
if(!x) x=Primelist[i];
else if(!y)
{
y=Primelist[i];
temp=y;
max=y-x;
flag++;
}
else
{
if(Primelist[i]-temp>max)
{
max=Primelist[i]-temp;
x=temp;
y=Primelist[i];
temp=Primelist[i];
}
else
{
temp=Primelist[i];
}
}
}
if(flag)
{
printf("%I64d,%I64d are closest, %I64d,%I64d are most distant.\n",a,b,x,y);
}
else
{
printf("There are no adjacent primes.\n");
}
}
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator