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 <iostream>
//#include <vector>
//#include <math.h>
//#include <string>
//#include <cmath>

int main(void);
int count_prime_number(int n);

int main(){
	int n;
	int cnt = 0;
	int result[30];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		result[cnt] = count_prime_number(n);
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i+= 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j+= 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[100003]={0};
	
	for(int i=2;i<100002;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)flag=false;
		}
		/*if(flag){
		cnt++;
		sosu[i]=cnt;
		}*/
		sosu[i]=(flag)? cnt++ : cnt;		
	}
	//for(int i=0;i<30;i++)cout<<sosu[i]<<" ";
	while(cin>>n){
	cout<<sosu[n]<<endl;
	}
    return 0;
}

C++: #include<stdio.h>
bool b[1000000];

int main(void)
{
    int a,n,i;
    int count=0;
    int f=1;

    for(i=3;i<1000000;i+=2){
        f=1;
        for(a=2;a*a<=i;a++){
            if(i%a == 0){
                f=0;
                break;

            }
        }
        if(f==1){
            b[i]=1;
        }
    }
    b[2]=1;

    while(scanf("%d",&n)!=EOF){
        for(i = 0; i <= n; i++){
            if(b[i]==1)count++;
        }

    printf("%d\n",count);
    count=0;
    }
    return 0;
}

C++: #include <stdio.h>

int main()
{
    unsigned long long int isprime ,n,i,x,z,sum=0;
    scanf("%llu",&x);
    for(n=2;n<=x;n++)
    {
        if(n==2)
        {
            sum++;
        }
        else
        {
            isprime=0;

            for(i=2;i<n;i++)
            {
                if(n%i==0)
                {
                    isprime=1;
                    break;
                }
            }
         }
        if(isprime == 0)
        {
            sum++;
        }
    }
    printf("%llu\n",sum);
    return 0;
}

C++: #include <stdio.h>

int ans ;
int N ;
bool prime[1000200] ;

void SE ( ) ;

int main ( ) 
{
	SE ( ) ;
	while ( scanf ( "%d" , &N ) == 1 ) {
		ans = 0 ;
		if ( N > 2 ) {
			ans++ ;
		}
		for ( int i = 3 ; i <= N ; i += 2 ) {
			if ( prime[i] == false ) {
				ans++ ;
			}
		}
		printf ( "%d\n" , ans ) ;
	}
	return 0 ;
}

void SE ( )
{
	prime[0] = prime[1] = true ;
	for ( int i = 3 ; i < 1004 ; i += 2 ) {
		if ( prime[i] == false ) {
			for ( int j = i * i ; j < 1000200 ; j += i * 2 ) {
				prime[j] = true ;
			}
		}
	}
}

C++: #include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include <sstream>
using namespace std;
int main(void){
    int n,ans,i;
    while(cin >> n){
        ans = 0;
        if(n < 2){
            cout << "0" << endl;
            continue;
        }else if(n == 2){
            cout << "1" << endl;
            continue;
        }else{
            ans++;
        }
        for(i = 3; i <= n; i += 2){
            double sqrti = sqrt(i);
            if(ceil(sqrti) == floor(sqrti)){
                continue;
            }
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;


int main()
{
	int n;
	vector<int> prime;
	
	for(int i=0;i<1000000;i++)
		prime.push_back(1);
	
	prime[0]=prime[1]=0;
	
	for(int i=0;i<1000000;i++)
	{
		if(prime[i]==1)
		{
//			cout << i << endl;
			
			for(int j=2;i*j<1000000;j++)
			{
				prime[i*j]=0;
//				cout << i*j <<endl;
			}
		}
	}
	
	
	for(;cin >> n;)
	{
		int ans=0;
		
		for(int i=0;i<=n;i++)
			if(prime[i]==1)
				ans++;
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include<vector>
using namespace std;
vector<int> p;
void makeprimelist(int n)
{
	bool *isp=new bool[++n];
	for(int i=0;i<n;i++)isp[i]=true;
	for(int i=2;i<=n;i++)
	{
		if(isp[i])
		{
			p.push_back(i);
			for(int j=2;j<=n/i;j++)isp[i*j]=false;
		}
	}
	return;
}

int main() {
	int n;
	while(cin>>n)
	{
		p.clear();
		makeprimelist(n);
		cout<<p.size()<<endl;
	}
	return 0;
}

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

using namespace std;

#define MAX 1000000

int main(void){

  int n,count = 0,num = 0;

  while(cin >> n){

    vector<int>array(MAX,0);

    if(n == 1){
      count = 0;
      cout << count << endl;
    }

    if(n == 2){
      count = 1;
      cout << count << endl;
    }

    if(n == 3){
      count = 2;
      cout << count << endl;
    }

    if(n > 3){
      count = 2;
      num = 0;
      array[num++] = 2; 
      array[num++] = 3; 


      for(int i = 5; i <= n ; i+=2){
        int flag = 0;
        for(int j = 0; array[j] * array[j] <= i;j++){
          if(i % array[j] == 0){
            flag = 1;
            break;
          }
        }
        if(!flag){
          array[num++] = i;
          count++;
        }
      }
      cout << count << endl;
      count = 0;
      num = 0;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000
int main( void )
{
	vector <bool> prime( MAX, false );
	prime[2] = true;
	for ( int i = 3; i * i <= MAX; i++ )
	{
		prime[i] = true;
	}

	for ( int i = 3; i <= MAX; i++ )
	{
		if ( prime[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				prime[j] = false;
			}
		}
	}

	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		int cnt = 1;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( prime[i] ) cnt++;
		}

		cout << cnt << endl;

	}

	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<int>primes;
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	vector<int>sos;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
	for (int i = 0; i <= amax; ++i) {
		if (sos[i]) {
			primes.push_back(i);
		}
	}
	flag = true;
}

int main() {
	hurui(1e6 + 5);
	int num;
	while (cin >> num) {
		auto it = upper_bound(primes.begin(), primes.end(),num);
		cout << it - primes.begin() << endl;
	}
	return 0;
}