Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

using namespace std;

#define REP(a, i, n) for (int i = a; i <= n; ++i)

bool isPrime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    if (n == 3) return true;
    if (n % 3 == 0) return false;

    for (int i = 5; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

//  n よりも小さい素数の数は何個存在するか
int main() {
    int n; // 10000
    scanf("%d", &n);

    int cnt = 0;
    REP(1, i, n) {
        if (isPrime(i)) cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}

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

std::vector<int> PRIMES;

void init_primes(int max)
{
  if (max < 2) return;
  std::set<int> candidate;
  PRIMES.push_back(2);
  for (int i = 3; i < max; i+=2) {
    candidate.insert(i);
  }
  for (int i = 3; i < sqrt(max); i+=2) {
    std::set<int>::iterator it = candidate.find(i);
    if (it != candidate.end()) {
      PRIMES.push_back(i);
      int del_num = i;
      while (del_num < max) {
        it = candidate.find(del_num);
        if (it != candidate.end()) candidate.erase(it);
        del_num += i;
      }
    }
  }
  for (std::set<int>::iterator it = candidate.begin();
       it != candidate.end(); ++it) {
    PRIMES.push_back(*it);
  }
}

int main()
{
  const int max = 100000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
}

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

using namespace std;

int main() {
  int n;

  while(1) {
    cin >> n;
    if(cin.eof()) break;
    int m = (int)sqrt(n);
    
    vector<bool> h(n+1, true);
    h[0] = false;
    h[1] = false;

    for(int i = 2; i <= m; i++) {
      if(h.at(i)) {
	for(int s = 2; s*i < h.size(); s++) {
	  if(h.at(s*i))
	    h[s*i] = false;
	}
      }
    }
    
    int ans=0;
    for(auto f : h) {
      if(f)
	ans++;
    }
    cout << ans << endl;
  }
  
  return 0;
}

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

int main(){
	int n;
	int a=0;
	cin >> n;
		for(int i = 1; i <= n; ++i){
			for(int j = 2; j <= i; ++j){

				if(i%j == 0){
				if(i==j){
					++a;
				}else{
					break;
				}
				}
		}
	
	}
		cout << a << '\n';
}

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

int main(void)
{
  bool notPrime[1000000];
  notPrime[1] = true;
  int primeNum[1000000];
  int i,j;
  for(i=2; i<1000000; ++i){
    if(!notPrime[i]){
      primeNum[i] = primeNum[i-1]+1;
      if(i<1000){
        for(j=i*2; j<1000000; j+=i){
          notPrime[j] = true;
        }
      }
    }else{
      primeNum[i] = primeNum[i-1];
    }
  }
        
  int n;
  while(scanf("%d", &n) != EOF){
    printf("%d\n", primeNum[n]);
  }

  return 0;
}

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

int main(){
  int n;
  bool prime[N];
  for(int i=0;i<N;i++) prime[i]=true;
  prime[0]=prime[1]=false;
  for(int i=0;i<N/2;i++){
    if(!prime[i]) continue;
    for(int j=i+i;j<N;j+=i) prime[j]=false;
  }
  while(cin>>n){
    int ans=0;
    for(int i=0;i<=n;i++)
      if(prime[i]) ans++;
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
bool F(int n)
{
	bool r=true;
	for(int i=2;i<=(n/2);i++)
	{
		if(n%i==0){
			r=false;
			break;
		}
	
	}	
	return r;
}

int main()
{
	int number=0;
	int result=0;
	while(1)
	{
		result=0;
		cin>>number;
		for(int i=number;i>=2;i--)
		{
			if(F(i)==true)
				result++;
		}
		cout << result <<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int a,i;
cin>>a;
for(int x=2x<a;x++){
if(a%x==0){i++}
cout<<i<<endl;
}
return 0;
}

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

#define N 1000000
int main() {
  vector<int> table(N,1);
  table[0]=table[1]=0;
  for (int i=2; i*i<N; i++)
    if (table[i])
      for (int j=i*2; j<N; j+=i)
        table[j] = 0;
  int n;
  while(cin>>n) {
    int ans=0;
    for (int i=2;i<=n;i++) {
      if (table[i]) ans++;
    }
    cout << ans << endl;
  }
}

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