Skip to content

Instantly share code, notes, and snippets.

@somratcste
Created December 24, 2014 15:02
Show Gist options
  • Save somratcste/acc792e40ddabc6488e0 to your computer and use it in GitHub Desktop.
Save somratcste/acc792e40ddabc6488e0 to your computer and use it in GitHub Desktop.
This problem is not accepted ,,,,,, i used seive algorithm but where is the problem i don't understand.
#include <stdio.h>
#include <math.h>
#define MAX 1900000
char prime[MAX];
int digitprime[MAX];
void seive()
{
int i,j,k,temp,update,m,d,sum;
for(i=2;i<=MAX;i++)
prime[i]=1;
k=2;
for(m=2;m<=sqrt(MAX);m++){
for(j=k+k;j<=MAX;j+=k)
prime[j]=0;
}
update = 0;
for(d=0;d<=MAX;d++){
if(prime[d]){
temp=d;
sum=0;
while(temp>=10){
sum+=temp%10;
temp/=10;
}
sum+=temp;
if(prime[sum])
update++;
}
digitprime[d] = update;
}
}
int main()
{
int test,up,low,n,sum;
seive();
scanf("%d",&test);
for(n=0;n<test;n++)
{
scanf("%d %d",&low , &up);
printf("%d\n",digitprime[up]-digitprime[low-1]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment