标签:
Description
Input
Output
Sample Input
Sample Output
1 #include<bits/stdc++.h> 2 #define ll __int64 3 #define mod 1e9+7 4 #define PI acos(-1.0) 5 #define bug(x) printf("%%%%%%%%%%%%%",x); 6 #define inf 1e8 7 using namespace std; 8 int n; 9 bool visit[100005]; 10 int prime[100005]; 11 int ans[100005]; 12 void fun() 13 { 14 memset(visit, true, sizeof(visit)); 15 int num = 0; 16 visit[1]=false; 17 for (int i = 2; i <= 100000; ++i) 18 { 19 if (visit[i] == true) 20 { 21 num++; 22 prime[num]=i; 23 //mp[i]=num; 24 } 25 for (int j=1;((j<=num)&&(i*prime[j]<= 100000));++j) 26 { 27 visit[i*prime[j]] =false; 28 if (i%prime[j]==0)break; //点睛之笔 29 } 30 } 31 int jishu=0; 32 for(int i=3;i<=100000;i++) 33 { 34 if(visit[i]&&visit[i-2]) 35 jishu++; 36 ans[i]=jishu; 37 } 38 ans[0]=0; 39 ans[1]=0; 40 ans[2]=0; 41 } 42 int main() 43 { 44 fun(); 45 while(scanf("%d",&n)!=EOF) 46 { 47 if(n<0) 48 break; 49 printf("%d\n",ans[n]); 50 } 51 return 0; 52 }
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5675017.html