标签:
Description
Input
Output
Sample Input
3 1 100 2 2 3 19
Sample Output
Case #1: 14 Case #2: 1 Case #3: 4
#include<cstdio> #include<cstring> #include<cmath> using namespace std; int ans=0; bool p[1000000]; int num[1000000]; void prime() { int i,j; memset(p,0,sizeof(p)); p[1]=1; for(int i=2; i<=1000000; i++) { if(!p[i]) { for(j=2; i*j<=1000000; j++) { p[i*j]=1; } } } } void biao() { int a,b,c,d,e,f,g; memset(num,0,sizeof(num)); for(int i=2; i<=1000000; i++) { if(!p[i]) { a=i/1000000; b=i%1000000/100000; c=i%100000/10000; d=i%10000/1000; e=i%1000/100; f=i%100/10; g=i%10; if(!p[a+b+c+d+e+f+g]) ans++; } num[i]=ans; } } int main() { int T,L,R; int a,b,c,d,e,f,g; int ans; int x=1; scanf("%d",&T); prime(); biao(); while(T--) { scanf("%d%d",&L,&R); printf("Case #%d: %d\n",x++,num[R]-num[L-1]); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/a1967919189/article/details/47731879