Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

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;
}

C++: #include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// エラストテネスの篩, o(n)程度
// n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか
int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr){
	bool flag0 = false, flag1 = false;
	if(prime == nullptr){
		flag0 = true; prime = new int[n];
	}
	if(is_prime == nullptr){
		flag1 = true; is_prime = new bool[n + 1];
	}

	int p = 0;
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;

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

	if(flag0) delete prime;
	if(flag1) delete is_prime;

	return p;
}


int main(void){
	int n;
	while(scanf("%d", &n)){
		cout << sieve(n) << '\n';
	}

	return 0;
}