Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #include <iostream>
#include <cmath>
using namespace std;

bool check(int in){
	for (int i = 3; i<=sqrt(in); i+=2){
		if (in % i == 0)
			return false;
	}
	return true;
}

int PrimeNumber(int in){
	int count = 0;
	if (in > 2)	count++;
	for (int i = 3; i <=in; i+=2){
		if (check(i))	count++;
	}

	return count;
}

int main(){
	int in;
	while (cin >> in, !cin.eof()){
		cout << PrimeNumber(in) << endl;
	}
}

C++: #include<stdio.h>
int main()
{
    long long n;
    while(scanf("%lld",&n)==1)
    {
       long long i,j,k,s=0;
       for(i=2;i<=n;i++)
    {

        k=0;
        if(i%2==0&&i!=2)
            k=1;
      for(j=3;j*j<=i&&k==0;j+=2)
      {
          if(i%j==0)
          {
              k=1;
              break;
          }
      }
       if(k==0)
          {
             ++s;
          }
    }
        printf("%lld\n",s);
    }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int num, cnt;
	unsigned int i, j;
	int data_num;
	unsigned int sq_num;
	unsigned int *prime;

	scanf("%d", &num);

	sq_num = (int)sqrt((double)num);
	prime = (unsigned int*)malloc(sizeof(unsigned int) * num);

	for (i = 0; i < num; i++) {
		prime[i] = 1;
	}

	prime[0] = 0;
	for (i = 1; i < sq_num; i++) {
		if (prime[i] == 1) {
			for (j = (i+1); (i+1) * j <= num; j++) {
			prime[(i+1) * j - 1] = 0;
			}
		}
	}

	cnt = 0;
	for (i = 0; i < num; i++) {
		if (prime[i] == 1) {
			cnt++;
			//printf("%d", i + 1);
		}
	}

	printf("%d\n", cnt);

	free(prime);

	return 0;

}

C++: #include<iostream>
using namespace std;

int main(){
 bool is_prime[1000000]; //?´???°???????????¨

 is_prime[0] = is_prime[1] = false;

 for(int i=2; i<1000000; i++){
  is_prime[i] = true;
 }

 for(int i=2; i*i<1000000; i++){
  if(is_prime[i]){
   for(int j=i*i; j<1000000; j+=i){
    is_prime[j] = false;
   }
  }
 }

 int n_prime[1000000]; //?´???°????????°?????¨

 int cnt = 0;

 for(int i=0; i<1000000; i++){
  if(is_prime[i]){
   cnt++;
  }
  n_prime[i] = cnt;
 }

 while(true){
  int n;
  cin >> n;

 if(cin.eof()) break;

 cout << n_prime[n] << endl;
 }

 return 0;
}

C++: #include <iostream>
using namespace std;



int main(){
	int i , j , n , pn;
	
	while(cin>>n){
		pn=1;
		for(i=3 ; i<=n ; i++){
			for (j=2 ; j<i ; j++){
				if (i%j==0) goto skip;
			}
			pn++;
			skip:;
		}
		if(n==0 || n==1 ) {
			cout << 0 << endl;
		} else {
			cout << pn << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
int main(){int m,n=999999,o,c=n/2+1,d,i,e;bool*v=new bool[c];memset(v,1,c);for(i=m=1;i<499;){for(m=i++;!v[m];)m++;for(o=m*2+1,d=o*3;d<n+1;d+=o*2)v[d/2]=0;}for(;!(std::cin>>n).eof();){e=n>1;n&1?n:--n;for(i=1;i<n/2+1;)e+=v[i++];printf("%d\n",e);}delete[]v;}

C++: #include<bits/stdc++.h>
using namespace std;

int f[1000001];
int main(){
    fill_n(f,1000001,1);
    f[0]=f[1]=0;
    
    for(int i=2;i<1000001;i++){
        f[i]+=f[i-1];
        if(!f[i])continue;
        for(int j=i+i;j<1000001;j+=i)f[j]=0;
    }
    
    int N;
    
    while(scanf("%d",&N)!=EOF){
        printf("%d\n",f[N]);
    }
    
    return 0;
    
}

C++: #include <iostream>
#define N 100000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<fstream>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<ctime>
#include<climits>
#include<ctype.h>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
#define PI acos(-1.0)
#define eps 1e-12
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ll N = 1e6+1;
const int MOD = 1e9+7;
bool flag = true;
int prime[N];
bool check[N]{0};
int main()
{
	//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
	//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
	//%%%llaa
    int i,j,n,tot=0;
    for(i=2;i<N;i++)
    {
        if(!check[i])
        {
            prime[tot++]=i;
            for(j=i+i;j<N;j+=i)
                check[j]=1;
        }
    }
    while(~scanf("%d",&n)&&n)
    {
        int num=0;
        i=0;
        while(prime[i++]<=n)
            num++;
        printf("%d\n",num);
    }
	return 0;
}


/*

*/

C++: #include<iostream>
#include<cmath>
#include<cstdio>
int main()
{
	using namespace std;
	int a[31]={0,0,1,2,2,3,3,4,4,4,4,5};
	int ans=0,t=0,n,i,j;

	while(scanf("%d",&n)!=EOF)
	{
		if(n<=11) cout<<a[n]<<endl;
		else
			for(j=12;j<=n;++j)
			{
				for(i=2;i<=(int)sqrt(n);++i)
			 		if(j%i==0) 
					{
						t=1;
						break;	
			 		}
				
				if(t==0) a[j]=a[j-1]+1;
			 		else 
					{
						t=0;
						a[j]=a[j-1];
					}	
			}
		
		if(n>11) cout<<a[n]<<endl;	
	}
	return 0;
}

C++: #include<cstdio>
#include<cmath>

bool isPrime(int n){
    if(n==2)
        return true;
    else if(!(n&1))
        return false;
    else if(n == 3 || n == 5 || n == 7)
        return true;
    else if(n%3 == 0 || n%5 == 0)
        return false;
    else{
        int root=sqrt(n);
        for(int i=7; i<=root; i+=2)
            if(n%i==0)
                return false;
    }
    return true;
}

int PrimeCounter(int n){
    int counter=0;
    for(int i=2; i<=n; i++){
        if(isPrime(i)){
            counter++;
        }
    }
    return counter;
}

int main()
{
    int n;
    while(scanf("%d", &n) != EOF){
        printf("%d\n", PrimeCounter(n));
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
bool prime[1000000];
void sieve() {
    fill_n(prime, 1000000, true);
    for (int i=2; i<=1000; ++i) {
        if (prime[i]) {
            for (int j=i*i; j<1000000; j+=i) {
                prime[j] = false;
            }
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    sieve();
    int n;
    while (cin >> n) {
        int cnt = 0;
        for (int i=2; i<=n; ++i) {
            if (prime[i]) {
                cnt ++;
            }
        }
        cout << cnt << "\n";
    }
    return 0;
}

C++: #include<iostream>
using namespace std;

int main(){

	bool is_prime[1000000];
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n_prime[1000000];
	
	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i]=cnt;
	}
	
	while(true){
	int n;
	cin>>n;
	
	if(cin.eof())
		break;
	
	cout<<n_prime[n]<<endl;
	}

	return 0;
}