Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	a, _ := strconv.Atoi(scanner.Text())
	return a
}

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

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

C++: #include<iostream>
#include<string.h>

using namespace std;

long long int seive(int n)
{
	bool arr[n+1];
	memset(arr, true, sizeof(arr));
	for(long long int i = 2; i*i <= n; i++){
		if(arr[i] == true){
			for(long long int j = 2*i; j <= n; j += i){
				arr[j] = false;
			}
		}
	}
	long long int cnt = 0;
	for(long long int i = 2; i <= n; i++){
		if(arr[i] == true){
			cnt++;
		}
	}
	return cnt;
}
int main()
{
	long long int n;
	
	cin >> n;
	
	cout << seive(n) << endl;
	
	
	return 0;
}

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

bool isChecked[1000010];
vector <int> prime;

int main() {
	for (int i = 0;i < 1000000; i++) isChecked[i] = false;
	isChecked[0] = true;
	isChecked[1] = true;
	for (int i = 2; i < 1000000;i++) {
		if(isChecked[i]) continue;
		prime.push_back(i);
		for (int j = 1; j * i < 1000000;j++) {
			isChecked[j*i] = true;
		}
	}
	int n;
	while(cin >> n) {
		int i;
		for(i = 0;;i++) {
			if (prime[i] > n) break;
		}
		cout << i << endl;
	}
	return 0;
}

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

int main()
{
	bool prm[N];
	for(int i=0; i<N; i++)
	{
		prm[i]=true;
         }
		int upto= (int) sqrt(N);
		for(int i=2;i<= upto; i++)
		{
			if(prm[i])
				for(int j=2; j*i<N; j++)
				{
				    prm[i*j]=false;
				}
		}
		int n;
		while(cin>>n)
		{
			int count=0;
			for(int i=2; i<=n; i++)
			{
				if(prm[i])
					count++;
			}
			cout<<count<<endl;
		}
	}
	return 0;
}

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

int main()
{
	
	long long int k,p[100000];
	long long int n=-1;
	p[0]=2;
	while(cin>>n){
	k=1;
	int r=(int)sqrt((float)n);
	//ツ確ツ認ツ用ツ素ツ青板づ債閉つ篠づ個づ慊づ必ツ要
	//ツ閉つ篠づ慊づづ慊づュツつキ
	for(int i=3;i<=r;i++){
		//ツつサツづェツづ慊づづ個素ツ青板づ確ツ認
		for(int j=0;j<k;j++){
			//ツ催甘コツづ慊づ環づェツづ按つゥツづつスツづァツカツウツδ督トツつオツづ、ツ確ツ認ツ用ツ素ツ青板づ個配ツ療アツづ可格ツ納
			if(i%p[j]==0){
				break;
			}else if(j==k-1){
				p[k]=i;
				k++;
			}
		}
	}
	long long int r_k=k;
	for(;r<=n;r++){
		for(long int i=0;i<r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==r_k-1){
				k++;
			}
		}
	}
	if(n==1){
		k=0;
		cout<<k<<endl;
	}else if(n==2){
		k=1;
		cout<<k<<endl;
	}else if(n==3){
		k=2;
		cout<<k<<endl;
	}else{
	cout<<k<<endl;
	}
	}
}

C++: std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     
        IsPrime.resize(max+1,true); 
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i)
        if(IsPrime[i]) 
            for(size_t j=2; i*j<=max; ++j) 
                IsPrime[i*j] = false;      
}

C++: #include<iostream>

using namespace std;

int main(){
        int n;
        int d;
        bool count;
        int number[400000];
        number[0] = 2;
        
        
        while(cin >>n != 0){
                d = 0;
                for(int i = 3; i <= n; i++){
                        count = true;
                        for(int j = 0; j <= d; j++)
                                if(i % number[j] == 0)
                                        count = false;
                        if(count == true){
                                d++;
                                number[d] = i;
                        }
                }
        cout << d+1 << endl;
        }
}

C++: #include<iostream>
using namespace std;
bool isprime(int n) {
	if (n < 2)return false;
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return true;
}
int main() {
	int x;
	while (cin >> x) {
		int cnt = 0;
		for (int i = 2; i <= x; i++) {
			if (isprime(i))cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){
	int n;
	int a[1000];
	int b;
	int i, j, p;
	int c[30];
	p = 0;
	while (scanf("%d", &n) != EOF){
		b = (int)pow((double)n, 0.5);
		c[p] = 0;
		a[0] = -1;
		for (i = 2; i <= b; i++){
			for (j = 2; j <= n / i; j++){
				a[i*j - 1] = -1;
			}
		}
		for (i = 1; i <= n; i++){
			if (a[i - 1] != -1){ c[p]++; }
			a[i - 1] = 0;
		}
		p++;
	}
	for (i = 0; i < p; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}

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

using namespace std;\

int main(void)
{
	int n = 1;
	int nMax = 1;
	
	vector<int> vecPrime;
	
	while(cin >> n){
		if(n > nMax){
			for(int i = nMax + 1; i <= n; i++){
				vecPrime.push_back(i);
			}
			nMax = n;
		}
		
		int rootN = floor(sqrt(n));
		for(int i = 2; i <= rootN; i++){
			for(int j = 0; j < vecPrime.size(); j++){
				if(vecPrime[j] % i == 0 && vecPrime[j] != i){
					vecPrime.erase(vecPrime.begin() + j);
					j--;
				}
			}
		}
		
		//素数の数をカウント
		int cnt = 0;
		int sizeVec = vecPrime.size();
		for(int i = 0; i < sizeVec; i++){
			if(vecPrime[i] > n){
				break;
			}
			cnt++;
		}
		cout << cnt << endl;
	}
	
	return 0;
}

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

#define FOR(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
using namespace std;

void solver() {
    int N;
    while(cin>>N){
        bool* isPrime=new bool[N+1];
        FOR(i,N+1)isPrime[i]=false;
        for (int i = 2; i <= N; ++i)
            isPrime[i] = true;
        for (int i = 2; i <= N; ++i) {
            if (isPrime[i])
                for (int j = 2 * i; j <= N; j += i)
                    isPrime[j] = false;
        }
        int cnt=0;
        FOR(i,N+1)if(isPrime[i])cnt++;
        delete[]isPrime;
        cout<<cnt<<endl;
    }
}

int main() {
    solver();
    return 0;
}

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

//素数かどうか判定する関数
bool judge( int x )
{

    for( int i = 2; i <= sqrt(x); i++ )       //与えられた数が10なら
    {                                         //
        if( x % i == 0)
            return false;
    }

    return true;
}

int main()
{
    int n;

    while( cin >> n )                           
    {
        bool PN[n+1];                           //PrimeNumber
        int count = 0;                          //countは素数の数


        PN[0] = false;                          //0は素数ではない。
        PN[1] = false;                          //1は素数ではない。

        for( int i = 2; i <= n; i++)            //0,1以外の全ては素数候補。ここから篩にかける。 
        {
            PN[i] = true;                       //ex.100の場合、2~100を素数候補とする
            count++;
        }

        for( int i = 2; i <= sqrt(n); i++)            
        {
            for( int j = 2; j <= n / i; j++ )
            {
                if( PN[i*j] == true )
                {
                    PN[i*j] = false;
                    count--;
                }

            }
        }
        cout << count << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int ar[1000009];
int pr[1000009];
int main()
{
    int i,n,j,k,z=2,te;
    for(i=4;i<=999999;i+=2){
        ar[i]=1;
    }
    //pr[2]=1;
    int sq=sqrt(1000000);
    for(i=3;i<=1000000;i+=2){

            if(ar[i]==0){pr[i+1]=z++;}
            if(i<=1000){
                if(ar[i]==0){
                    for(j=i*i;j<=1000000;j+=2*i){
                        ar[j]=1;
                    }
                }
            }
    }
    for(i=0;i<1000000;i++){
        if(pr[i]!=0){
            te=pr[i];
        }
        pr[i]=te;
    }


    while(scanf("%d",&n)==1){
        printf("%d\n",pr[n+1]);
    }
    return 0;

}