标签:
美素数
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=1000005;
int vis[maxn],ans[maxn];
void prime()
{
memset(vis,0,sizeof(vis));
memset(ans,0,sizeof(ans));
for(int i=2;i<maxn;i++)
{
if(vis[i])
continue;
for(int j=i+i;j<maxn;j+=i)
vis[j]=1;
}
}
int count_sum(int a)
{
int sum=0;
while(a)
{
sum+=a%10;
a/=10;
}
return sum;
}
int main()
{
prime();
ans[0]=ans[1]=0;
for(int i=2;i<maxn;i++)
{
if(!vis[i]&&!vis[count_sum(i)])
ans[i]=ans[i-1]+1;
else
ans[i]=ans[i-1];
}
int t,kase=0;
scanf("%d",&t);
while(t--)
{
int l,r;
scanf("%d%d",&l,&r);
printf("Case #%d: %d\n",++kase,ans[r]-ans[l-1]);
}
}
标签:
原文地址:http://www.cnblogs.com/xl1164191281/p/4748716.html