Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

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

const int maxn = 1e6 + 10;
typedef long long LL;

int p[maxn];
bool l[maxn];

int prime() {
    int cnt = 0;
    for(int i = 2; i < maxn; ++i) {
        if(!l[i]) {
            p[cnt++] = i;
            LL con = i;
            LL j;
            while((j = i * (con++)) < maxn) {
                l[j] = true;
            }
        }
    }
    return cnt;
}

int main() {
    int cnt = prime();
    int n;
    while(scanf("%d", &n) != EOF) {
        int ans = upper_bound(p, p + cnt, n) - p;
        printf("%d\n", ans);
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

vector<lint> primearray(lint N) {
	//N以下の素数を列挙
	vector<lint> R;
	vector<bool> prime;
	for (int i = 0; i <= N; i++) {
		prime.push_back(true);
	}
	if (N < 2) {
		return R;
	}
	prime[0] = false;
	prime[1] = false;
	for (lint i = 2; i * i <= N; i++) {
		if (!prime[i])continue;
		for (int j = 2 * i; j <= N; j += i) {
			prime[j] = false;
		}
	}
	for (lint i = 0; i < prime.size(); i++) {
		if (prime[i]) {
			R.push_back(i);
		}
	}
	return R;
}

int main() {
	lint N;
	while (cin >> N) {
		cout << primearray(N).size() << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

bool a[1000000];

int main()
{
    memset(a, true, sizeof(a));

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

    int n;
    while (~scanf("%d", &n)) {
        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += a[i];
        printf("%d\n", cnt);
    }
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n;

  while(!cin.eof()) {
    cin >> n;

    int m = (int)sqrt(n);
    
    vector<bool> h(n+1, true);
    h[0] = false;
    h[1] = false;

    for(int i = 2; i <= m; i++) {
      if(h.at(i)) {
	for(unsigned int s = 2; s*i < h.size(); s++) {
	  if(h.at(s*i))
	    h[s*i] = false;
	}
      }
    }
    
    int ans=0;
    for(auto f : h) {
      if(f)
	ans++;
    }

    cout << ans << endl;
  }
  return 0;
}

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

int main() {
	int n, count;
	bool *data;

	while (cin >> n) {
		data = new bool[n + 1];
		count = 0;
		data[0] = data[1] = false;
		for (int i = 2;i <= n;i++) {
			if (data[i]) {
				count++;
				for (int j = i + i;j <= n;j += i) {
					data[j] = false;
				}
			}
		}
		cout << count << endl;
		delete[] data;
	}
	return 0;
}

C++: #include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>


/*
	HOME-  Volume0-0009
	Submit Statistics
	 
	PCK 2003
	Prime Number
	Time Limit : 1 sec, Memory Limit : 32768 KB
	English version is here
	Prime Number

	6 ÈºÌ³Ì® n ðüÍµAn ÈºÌfª¢­Â é©ðoÍ·évOðì¬µÄº³¢B½¾µAfÆÍ 1 Æ©ª©gÅµ©èØêÈ¢³Ì®Ì¤¿ 1 ðÌ¼¢½àÌð¢¢Ü·Bá¦Î 10 ÈºÌfÍA2, 3, 5, 7 Å·B
	Input

	¡Ìf[^Zbgª^¦çêÜ·Bef[^ZbgÉ n ªPsÉ^¦çêÜ·BüÍÌÅãÜÅµÄº³¢B
	Output

	ef[^Zbg²ÆÉAn ÈºÌfÌÂðPsÉoÍµÄº³¢B
	Sample Input

	10

	Output for the Sample Input

	4

*/

using namespace std;


int main()
{
	string s;
	
	while (getline(cin, s))
	{
		int n;
		sscanf(s.c_str(), "%ld", &n);
		
		vector<int> v(n, 1);
		v[0] = 0;
		v[1] = 0;

		int x = n - 2;

		for (int i = 2; i <= n; i++)
		{
			if (0 == v[i])
			{
				continue;
			}
			for (int k = i * i; k <= n; k++)
			{
				if (0 == (k % i))
				{
					if (1 == v[k])
					{
						x--;
					}
					v[k] = 0;
				}
			}
		}
		
		printf("%d\n", x);
	}

	return 0;
}

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

bool isPrime(int k) {
    for(int i = 2; i < k; i++){
        if(k%i == 0) 
            return false;
    }
    return true;
}

int main() {
    int n;
    int count = 0;
    while(cin>>n) {
        for(int i = 2; i <= n;i++) {
            if(isPrime(i))
                count++;
        }
        cout<<count<<endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int count=0;
		for(int prime=2; prime<=n; prime++)
		{
			if(prime==2)
			{
				count++;
			}
			else
			{
				int i;
				for(i=2; i<prime; i++)
				{
					if(prime%i==0)
						break;
				}
				if(i==prime)
					count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include <iostream>

#define rep(i, n) for(int i = 2; i < n; i ++)

using namespace std;

int main(void){
	const int N = (int)1e6;
	bool num[N];
	rep(i, N) num[i] = true;
	for(int i = 2; i * i < N; i ++) if(num[i]) for(int j = i; i * j < N; j ++) num[i * j] = false;

	for(int n, count = 0; cin >> n; cout << count << endl, count = 0)
		rep(i, n + 1) if(num[i]) count ++;

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
#define MAXNUM 1000000
using namespace std;

bool num[MAXNUM];
void erast(int n){
  FOR(i, 2, floor(sqrt(n))+1){
    if(num[i]){
      FOR(j, 2, n){
        if(i*j>=MAXNUM) break;
        num[i*j] = false;
      }
    }
  }
}

int main(){
  int n;
  REP(i, MAXNUM)  num[i] = true;
  num[0]=false;
  num[1]=false;
  while(cin >> n){
    int ans=0;
    erast(n);
    REP(i, n+1){
      if(num[i]){
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

#define pb push_back

using namespace std;

const int MAX=100000;
int main(void)
{
	int x;
	bool p[MAX];
	int cnt;
	int i1,i2;

	fill(p,p+MAX,false);

	for(i1=2;i1<MAX;i1++){
		for(i2=2;i2*i2<=i1;i2++){
			if(i1%i2==0) break;
		}
		if(i2*i2>i1) p[i1]=true;
	}

	while(1){
		cin>>x;
		if(x==EOF) break;

		cnt=0;
		for(i1=0;i1<=x;i1++){
			if(p[i1]) cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

int main()
{
	bool num[1000000] ;
	for( int i = 0 ; i < 1000000 ; i ++ )
	{
		num[i] = false ;
	}

	int count = 0 ;
	int get ;
	while( cin >> get )
	{
		for( int i = 2 ; i <= get ; i ++ )
		{
			if( num[i] == false )
			{
				for( int j = 1 ; j < (get/i) ; j ++ )
				{
					num[i+(j*i)] = true ;
				}

				count ++ ;
			}
		}
		cout << count << endl ;
		count =  0 ;

		for( int i = 0 ; i < get ; i ++ )
		{
			num[i] = false ;
		}
	}

	return 0 ;
}