View Code of Problem 27

#include<cstdio>
#define max 1000000

bool prime[max+1];
__int64 sum[max+1];

int main()
{
__int64 tmp=0;
int a,b,i,j;
prime[0]=prime[1]=1;
sum[1]=0;
for(i=2;i<=max;i++)
{
if(!prime[i])
{
for(j=i+i;j<=max;j+=i)
prime[j]=1;
tmp+=i;
}
sum[i]=tmp;
}
while(scanf("%d%d",&a,&b)!=EOF)
{
if(a>b)
{
tmp=a;
a=b;
b=tmp;
}

for(i++;i<=b;i++)
if(!prime[i]) printf(" %d",i);
printf("%I64d\n",sum[b]-sum[a-1]);
}
return 0;
} 
/*
Main.c:1:9: fatal error: cstdio: No such file or directory
 #include<cstdio>
         ^~~~~~~~
compilation terminated.
*/

Double click to view unformatted code.


Back to problem 27