标签:
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h>
const int N=1000000;
int a[N];
int prim(int x)
{
int i;
if(x==2)
return 1;
for(i=2;i*i<=x;i++)
if(x%i==0)
return 0;
return 1;
}
int main()
{
int j=0,i,v,m,n,sum,count,f=1;
a[j++]=2;
for(i=3;i<=1000000;i+=2)
if(prim(i))
{
int t=i;
sum=0;
while(t)
{
sum+=t%10;
t/=10;
}
if(prim(sum))
{
a[j++]=i;
}
}
scanf("%d",&v);
while(v--)
{
scanf("%d%d",&m,&n);
count=0;
for(i=0;a[i]<=n;i++)
if (a[i]>=m&&a[i]<=n)
count++;
printf("Case #%d: %d\n",f++,count);
}
return 0;
}
2015 HUAS Summer Trainning #6~H
标签:
原文地址:http://www.cnblogs.com/chenchunhui/p/4737769.html