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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

C++: #include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>
#include <array>
#include <utility>
#include <functional>

using namespace std;
typedef long long Int;
#define REP(i , x) for(int i = 0 ; i < x ; ++i)

typedef pair<int, int> P;

bool dp[10000100];

int main()
{
	int N;
	while (cin >> N){
		long ans(0);
		dp[0] = dp[1] = true;
		for (int i = 2; i <= N*N; ++i){
			if (!dp[i]){
				for (int j = 2*i; j <= N; j += i)
					dp[j] = true;
			}
		}
		for (int i = 2; i <= N; ++i){
			ans += !dp[i];
		}
		cout << ans << endl;
	}
}

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

int main(){
	int num, cou, i, j, flag;
	
	while(cin >>num){
		cou = 0;
		for(i = 3; i < num; i+= 2, flag = 0){
			for(j = 3; j < sqrt(num); j += 2){
				if(i % j == 0){
					flag = 1;
					break;
				}
			}
			if(flag == 0) cou++;
		}
		cout <<cou + 2<<endl;
	}
	
	return 0;
}

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

int main(){
	int m=0,n;
	cin>>n;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
	return 0;
}

C++: #include <stdio.h>

int main(){
	int sosuu[] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	
	while (scanf("%d", &n)!=EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0)break;
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int tmp;
	while (cin >> tmp)
	{
		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;

		prime.clear();
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

const int MAX = 1000000;
int N;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);

    vector<bool> is_prime(MAX,true);
    vector<int> prime(MAX,0);
    is_prime[0] = is_prime[1] = false;
    prime[0] = prime[1] = 0;
    int p = 0;
    for(int i = 2; i < MAX; ++i){
        if(is_prime[i]){
            for(int j = i*2; j < MAX; j += i) is_prime[j] = false;
        }
    }

    for(int i = 1; i < MAX; ++i){
        prime[i] = prime[i-1] + is_prime[i];
    }

    while(cin >> N){
        cout << prime[N] << '\n';
    }
    return 0;
}

C++: #include <stdio.h>

int primes[78498], primepis[1000000], num_primes;
int calculated;
int mysqrt(unsigned int x) {
	int a = 0, c = 0, y = 0, i = 0, t = x;
	while (t >>= 1) {
		++i;
	}
	for (i += i & 1; i >= 0; i -= 2) {
		c = (y << 1 | 1) <= x >> i;
		a = a << 1 | c;
		y = y << 1 | c;
		x -= c * y << i;
		/* if(c){
		  x -= y << i;
		} */
		y += c;
	}
	return a;
}
int main() {
	primes[0] = 2;
	primepis[2] = 1;
	calculated = 2;
	num_primes = 1;
	for (unsigned int i = 3; i <= 999999; i += 2) {
		bool is_prime = true;
		int max = (int)(mysqrt(i)) + 1;
		for (int j=1; primes[j] < max && j<num_primes; j++) {
			if (i%primes[j] == 0) {
				is_prime = false;
				break;
			}
		}
		if (is_prime) {
			primes[num_primes++] = i;
			primepis[i] = primepis[i + 1] = primepis[i - 1] + 1;
		}
		else {
			primepis[i] = primepis[i + 1] = primepis[i - 1];
		}
	}
	while (true) {
		int n;
		if (!scanf("%d", &n)) break;
		printf("%d\n", primepis[n]);
	}
}

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

int main(){
  int n;
  int num[1000000]={0};
  num[0]=1;
  num[1]=1;

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

  while(scanf(" %d",&n)!=EOF){
    int cnt=0;
    for(int i=2;i<=n;i++){
      if(num[i]==0){
	cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

#define maxn 999999 + 5
typedef long long ll;

int prime[maxn];

void init(){
    for(int i=2;i<maxn-4;i++)
        prime[i] = i % 2;
    prime[2]=1;
    prime[1]=0;
    for(int i=2;i*i<=maxn;i++){
        if(!prime[i])continue;
        for(int j=i;j*i<=maxn;j++)
            prime[i*i]=0;
    }
    for(int i=2;i<=maxn;i++)
        prime[i] += prime[i-1];
}
int main(){
    int n;
    init();
    
    while(~scanf("%d",&n))
        printf("%d",prime[n]);
    return 0;
}

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

int main()
{
   int n;
   int prime[1000000] = {1,1};
   int a=2;
   vector<int> r;
   while (scanf("%d",&n) != EOF)
   {
      int count=0;
      for (int i=a; i<=sqrt(n); i++)
      {
	 if (prime[i] == 0)
	 {
	    for (int j=i*2; j<1000000; j+=i)
	    {
	       prime[j] = 1;
	    }
	 }
	 a=i;
      }
      for (int i=2; i<=n; i++)
      {
	 if (prime[i] == 0)count++;
      }
      r.push_back(count);
   }
   for (int i=0; i<r.size(); i++)
   {
      cout << r[i] << endl;
   }
   return 0;
}

C++: #include<iostream>

using namespace std;

int n;

int main()
{
	while(cin>>n)
	{
		int count = 0;
		bool *flag = new bool[n]();
		for(int i=2;i<=n;++i)
		{
			if (flag[i]==true)
			{
				continue;
			}
			for(int j=i*2; j<n; j+= i)
			{
				flag[j] = true;
			}
		}

		for(int i=2;i<n;i++)
		{
			if(flag[i]==false)
			{
				++count;
			}
		}
		cout<<count<<endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;


int main(){
	int n = 0;
	int count;
	bool flag = false;

	while(cin >> n){
		count = 1;
		for(int i = 3; i <= n; i += 2){
			for(int j = 3; j * j <= i; j += 2){
				if(i % j == 0){
					flag = true;
					break;
				}
			}
			if(flag != true){
				count++;
			}
			flag = false;
		}
		cout << count << endl;
	}

	return 0;
}

C++: /*
Volume0-0009
*/
#include <iostream>
#include <stdlib.h>
#include <string.h>

#define N 1000000
#define TRUE (int)(0==0)
#define FALSE !TRUE

using namespace std;

int main(int argc, char *argv[]){
  int f[N];

  //  memset(f, TRUE, N);
  f[0]=FALSE;
  f[1]=FALSE;
  for (int i=2; i<N; i++)
    f[i] = TRUE;

  for (int i=2; i<N; i++){
    if (f[i] == TRUE ) {
      for (int j=i+i; j<N; j+=i){
	f[j] = FALSE;
      }
    }
  }
  int n;
  while (cin >> n) {
    int m = 0;
    for (int i=1; i<=n; i++){
      if (f[i]){
	m++;
      }
    }
    cout << m;
  }
 
  exit(0);
}