标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 415 Accepted Submission(s): 220
1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<queue> 5 #include<set> 6 #include<math.h> 7 #include<string.h> 8 using namespace std; 9 typedef long long LL; 10 bool prime[1000005]; 11 int sum[1000005]; 12 int main(void) 13 { 14 int i,j; 15 memset(sum,0,sizeof(sum)); 16 for(i = 2; i <=1000; i++) 17 { 18 if(!prime[i]) 19 { 20 for(j = i; (i*j) <= 1000000; j++) 21 { 22 prime[i*j] = true; 23 } 24 } 25 } 26 for(i = 0;; i++) 27 { 28 int x = 3*i*i+3*i+1; 29 if(x > 1e6) 30 break; 31 if(!prime[x]) 32 { 33 sum[x] = 1; 34 } 35 }sum[1] = 0; 36 for(i = 1; i <= 1e6; i++) 37 { 38 sum[i] += sum[i-1]; 39 } 40 int n; 41 while(scanf("%d",&n)!=EOF) 42 { if(sum[n]) 43 printf("%d\n",sum[n]); 44 else printf("No Special Prime!\n"); 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/zzuli2sjy/p/5924921.html