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 <stdio.h>
#include <vector>
#include <math.h>
using namespace std;
int main(void) {
  int num;
  while(scanf("%d", &num)==1) {
    vector<int> A;
    int ans;
    int count = 0;
    for (int i = 0; i < num - 1; i++) {
      A.push_back(i+2);
    }
    for (int i = 0; i < num - 1; i++) {
      if(A[i] != 0) {
      int k = 2;
      while(k*A[i] < num + 1) {
        if(A[k*A[i]-2] != 0) {
          A[k*A[i]-2] = 0;
          count++;
        };
        k++;
      }
    }
      if(i > sqrt(num)) break;
    }
    ans = num - 1 - count;
    printf("%d\n",ans);
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

#define MAX 1000000

int main(){
  int n;
  bool p[MAX];
  p[0] = false;
  p[1] = true;
  for(int i=2;i<MAX;i++)p[i] = true;
  for(int i=2; i*i<MAX;i++){
	if(p[i]){
	  for(int j=2*i;j<=MAX;j=j+i){
		p[j] = false;
	  }
	}
  }
  
  while(cin >> n){
	int cnt = 0;
	for(int i = 0;i<n;i++){
	  if(p[i]) cnt++;
	}
	cout << cnt << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <iostream>
#include <string.h>
#include <map>
#include <set>
#include <functional>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
    int n = 1000000;
	vector<bool> is_prime(n, true);
    vector<int> count(n);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<n; i++){
        if(is_prime[i]){
            for(int j=i; j<n; j+=i)
                is_prime[j] = false;
            count[i]++;
        }
        count[i] += count[i-1];
    }
    
    int a;
    while(cin>>a){
        cout << count[a] << endl;
    }
    
	return 0;
}

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

bool IsPrime(int p)
{
	for (int i = 2; i <= sqrt(p); i++)
	{
		if (p % i == 0) return false;
	}
	return true;
}

int main()
{
	int n;
	while (cin >> n)
	{
		int ans = 0;
		for (int i = 2; i <= n; i++)
		{
			if (IsPrime(i)) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    const int N = 1000000;
    vector<bool> vec(N, true);
    int limit = 1000;
    for (int i = 2; i < limit; i++){
        for (int j = 2; i * j < N; j++){
            vec[i * j] = false;
        }
    }
    int n, cnt = 0;
    while (cin >> n){
        for (int i = 2; i <= n; i++){
            if (vec[i])cnt++;
        }
        cout << cnt << endl;
        cnt = 0;
    }
}

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

int main(){
  int n,prime[1000001],key,lf=0;
  prime[0]=2;
  key=1;
  for(int i=3;i<=999999;i+=2)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      lf=1;
	      break;
	    }
	}
      if(lf == 1)
	{
	  lf=0;
	}
      else 
	{
	  prime[key]=i;
	  key++;
	}
    }

  while(cin >> n)
{
  int cou=0;
  for(int i=0;;i++)
    {
      if(prime[i] <= n)
	{
	  cou++;
	}
      else break;
    }

  cout << cou << endl;
 }
}

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

using namespace std;

const int N_MAX = 1000000;
int table[N_MAX];

int main() {
  table[0] = table[1] = 1;
  int sq = sqrt(N_MAX);
  for (int i = 2; i < sq+1; i++) {
    if (table[i] == 0) {
      for (int j = i*2; j < N_MAX; j += i) {
        table[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n) {

    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (table[i] == 0) ans++;
    }
    cout << ans << endl;

  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int d[1000000]={},p[1000000]={};
int main(){
	int n;
	for(int i=2;i<1000000;i++){
		if(d[i]==0){
			for(int j=2;i*j<1000000;j++){
					d[i*j]=1;
			}
		}
	}
	for(int i=2;i<1000000;i++){
		if(d[i]==0)
		p[i]=p[i-1]+1;
		else
		p[i]=p[i-1];
	}
	while(cin>>n,n){
		cout<<p[n]<<endl;;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int get_numprime( int num );
bool prime( int n );


int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		cout << get_numprime( num ) << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 0;

	for( int i = 2 ; i <= num ; i++ )
	{
		if( prime(i) ) numprime++;
	}

	return numprime;
}

bool prime( int n )
{
	for( int i = 2 ; i <= n/2 ; i++ )
	{
		if( n%i == 0 )
		{
			return false;
		}
	}
	return true;
}

C++: #include <iostream>

int main() {
    int n;
    while (std::cin >> n) {
        int primes = 0; // n以下の素数の数
        for (int i = 2; i <= n; i++) {
            bool flag = false; // はずれの目印
            for (int j = 2; j < i; j++)
                if (!(i % j)) {
                    flag = true;
                    break;
                }   
            if (!flag)
                 primes++;
        }
        std::cout << primes << std::endl;
     }   
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

bool prime[1000000];
int ans[1000000];

void is_prime(){
  rep(i,1000000)prime[i]=true;
  prime[0]=prime[1]=false;
  REP(i,2,1000000){
    if(prime[i]==true){
      for(int j=i+i;j<1000000;j+=i)prime[j]=false;
    }
  }
  if(debug)rep(i,1000)if(prime[i])cout<<i<<endl;
}

void calc(){
  ans[0]=0;
  REP(i,1,1000000){
    ans[i]=ans[i-1]+prime[i];
  }
}

int main(){
  int n;
  is_prime();
  calc();
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp;
	
	
//	vector<int> isPrime;
	bool isPrime[1000000];
	
	while(cin>>n)
	{
		for(int i = 0; i < n+1; i++){
//			isPrime.push_back(1);
			isPrime[i] = 1;
		}
//		cout << "Corecced!" << endl;
		isPrime[0] = isPrime[1] = 0;
		temp = 0;
		
		for(;;)
		{
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n+1; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i*head < n+1; i++){
				isPrime[i*head] = 0;
			}
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
		//	printf("head:%d    fin:%d\n",head,fin);
			
			if(fin <= head*head){
				break;
			}
			temp = head;
		}
		
		int cont = 0;
		for(int i = 0; i < n+1; i++){
			if(isPrime[i] == 1){
				cont++;
		//		cout << "+"<<i << endl;
			}
		}
		printf("%d\n",cont);
	}
}