Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

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

static int GetPrimeNumberNum(int maxValue);

int main(void)
{
  int n;
  
  while (std::cin >> n) {
    std::cout << GetPrimeNumberNum(n) << std::endl;
  }
  
  return 0;
}

static int GetPrimeNumberNum(int maxValue)
{
  std::vector<int> searchList;
  std::vector<int> primeList;
  
  for (int i = 2; i <= maxValue; i++) {
    searchList.push_back(i);
  }
  
  double maxValueSq = sqrt((double)maxValue);
  
  while (true) {
    int newPrime = searchList.at(0);
    
    if (newPrime > maxValueSq) {
      break;
    }
    
    primeList.push_back(newPrime);
    
    for (std::vector<int>::iterator it = searchList.begin();
         it != searchList.end();
         ) {
      if (*it % newPrime == 0) {
        it = searchList.erase(it);
      }
      else {
        ++it;
      }
    }
  }
  
  for (std::vector<int>::iterator it = searchList.begin();
       it != searchList.end();
       ++it) {
    primeList.push_back(*it);
  }
  
  searchList.clear();
  
  return primeList.size();
}

C++: #include <iostream>

using namespace std;

#define LN 1000001
 
int main()
{
    int n;
    static int pn[LN];
    
    for (int i = 0; i < LN; i++){
        pn[i] = 1;
    }
    
    pn[0] = pn[1] = 0;
     
    for (int i = 2; i * i < LN; i++){
        if (pn[i] == 1){
            for (int j = i * i; j < LN; j += i){
                pn[j] = 0;
            }
        }
    }
     
    for (int i = 1; i < LN - 1; i++){
        pn[i + 1] += pn[i];
    }
     
    while (cin >> n){
        cout << pn[n] << endl;
    }
     
    return (0);
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;
 
int isPrime(int n){
	//sieve of Eratosthenes
	if(n==2) return 1;
	if(n%2==0 || n<2){
		return 0;
	}

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

}

//0009
int main()
{
	int n;

	while(scanf("%d",&n)){
		
		int cnt = 0;
		for(; n>1; n--){
			if(isPrime(n))
				++cnt;
		}
		cout << cnt << endl;
	}
  return 0;
}

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

#define N 1000000L
bool num[N];

void furui(){
  long int i;
  int divide;
  int rt = 1000;
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for(divide = 2; divide < rt; divide++){
    if(num[divide] == false) continue;
    for( i = divide; i < N; i+= divide){
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0; ;i++){
      c = getchar();
      if(c == EOF || c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == 1) count++;
    }
    std::cout << count << std::endl;
    if(c == EOF) break;
  }
  return 0;
}

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

bool sieve[1000000];
void makesieve();

int main()
{
	makesieve();
	while(1)
	{
		int n,ans=0;
		std::cin>>n;
		if(std::cin.eof())break;
		for(int i=2;i<=n;i++)
		{
			ans+=sieve[i]?1:0;
		}
		std::cout<<ans<<std::endl;
	}
	return 0;
}

void makesieve()
{
	memset(sieve,-1,sizeof(sieve));
	sieve[0]=false;sieve[1]=false;
	for(int i=2;i<1000000;i++)
	{
		for(int j=i*2;j<1000000;j+=i)
		{
			sieve[j]=false;
		}
	}
}

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

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;

while(~scanf("%d",&n)){
int res=0;
for(int i=2;i<=n;i++){
if(is_prime(n)) res++;
}
printf("%d\n",res);
}
}

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

int main(){
  bool a[1000000];

  a[0]=a[1]=false;
  for(int i=2;i<1000000;i++){
    a[i]=true;
  }

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

  int n[1000000];

  int tmp=0;
  for(int i=0;i<1000000;i++){
    if(a[i]){
      tmp++;
    }
    n[i]=tmp;
  }

  while(true){
    int m;
    cin>>m;

    if(cin.eof()){
      break;
    }

    cout<<n[m]<<endl;

  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int main(k<30){
	int N,count=0,k;
	while(){
		cin >> N;
		count = 0;
		if(N<0)	break;
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
		k++;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool prime[1000100]={0};
int main(){
    int N;
    prime[1]=1;
    for(int i=2;i*i<1000000;i++){
        if(prime[i]==0){
            for(int j=i;j<1000000;j+=i){
                prime[j]=1;
            }
        prime[i]=0;
        }
    }
    while(~scanf("%d",&N)){
        int cnt=0;
        for(int i=1;i<=N;i++){
            if(prime[i]==0)cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

#define Max 1000000

int isPrime[Max];

int main(){
    int num;
    int i;

    isPrime[0] = isPrime[1] = 0;
    for(i = 2; i < Max; ++i){
        isPrime[i] = 1;
    }
    
    for(i = 3; i < Max; ++i){
        if(i % 2 == 0){
            isPrime[i] = 0;
        }
    }

    for(i = 4; i < Max; ++i){
        if(i % 3 == 0){
            isPrime[i] = 0;
        }
    }

    for(i = 6; i < Max; ++i){
        if(i % 5 == 0){
            isPrime[i] = 0;
        }
    }

    for(i = 8; i < Max; ++i){
        if(i % 7 == 0){
            isPrime[i] = 0;
        }
    }

    isPrime[2] = isPrime[3] = isPrime[5] = isPrime[7] = 1;

    while(cin >> num){
        int count = 0;
        for(i = 0; i <= num; ++i){
            if(isPrime[i] == 1){
                count++;
            }
        }
        cout << count << endl;
    }
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i;
	if(x == 2){
 		return 1;
	}
  	if(x<2||x%2==0){
		return 0;
	}
	i = 3;
	while( i <= sqrt(x) ){
		if(x%i==0){
			return 0;
		}
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i++){
			if(isprime(i)){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <array>
#include <cstdlib>
#include <cmath>

int main() {
	std::array<bool, 1000000> is_prime_table = { false, false, true };
	for( int i=3; i<=is_prime_table.size(); i+=2 ) {
		is_prime_table[i] = [&i]() -> bool
		{
			for( int j=3; j<=std::sqrt(i); j+=2 )
				if ( i % j == 0 )
					return false;
			return true;
		}();
	}
	
	int num = 0;
	while( std::cin >> num ) {
		int result = num > 1 ? 1 : 0;	// 2
		
		for( int i=3; i<=num; i+=2 )
			if ( is_prime_table[i] )
				++result;

		std::cout << result << std::endl;
	}
}

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

int a[999999]={};

int main(){
	int n,ans=0;
	vector<int> v;
	for(int i = 2; i*i < 999999; i++){
		for(int j = 0; j < 999999; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		v.push_back(n);
	}
	for(int i = 0; i < v.size(); i++){
		for(int j = 2; j <= v[i]; j++){
			if(a[j]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}