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

}

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

bool isPrime(int);

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

bool isPrime(int x) {
	if (x % 2 == 0)
		return true;
	for (int j = 3; j <= sqrt((double)x); j += 2) {
		if (x % j == 0)
			return false;
	}
	return true;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[999999]={0,0,1,2},n,k=0,count=2;
	for(int i=4;i<999999;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){k++;break;}
		}
		if(k==0)count++;
		a[i]=count;
		k=0;
	}
	while(cin>>n)cout<<a[n]<<endl;
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

int prime(int n) {
  int k;
  for(k = 2; k * k <= n; k++) {
    if(n % k == 0) return 0;
  }
  return 1;
}

int cntPrime(int n) {
  int cnt = 0, i, k;
  for(i = 2; i <= n; i++) {
    cnt += prime(i);
  }
  return cnt;
}

int main() {
  int a;
  int arg[1024] = { 0 };
  int cnt = 0;
  while(scanf("%d", &a) != EOF) {
    printf("%d\n", cntPrime(a));
  }
  int i;
  for(i = 0; i < cnt; i++) {
  }
}
~