Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

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

C++: int count_prime( unsigned int const& n )
{
    if ( n <= 0 || 1000000 <= n ) return -1;
    std::vector<bool> memo_prime( n+1, true );
    for ( unsigned int i = 2; i < n; ++i )
    {
        for ( unsigned int j = 2; i*j <= n; ++j )
        {
            memo_prime.at(i*j) = false;
        }
    }
    memo_prime.at(0) = memo_prime.at(1) = false;
    memo_prime.at(2) = true;
    return std::count( memo_prime.begin(), memo_prime.end(), true );
}

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

C++: #include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<=MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

int main(){
    init();
    int num;
    while(scanf("%d", &num) != EOF){
        int count=0;
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int A[30] = {};
	int P[1000000] = {};
	int i = 0, k;
	while (cin >> k) A[i++] = k;
	int c = 0, j;
	for (int k = 2; k < 1000000; ++k){
		if (P[k] == 0){
			P[k] = ++c;
			for (j = 2; j * k < 1000000; ++j)
				P[j * k] = -1;
		}
		else if (P[k] == -1)
			P[k] = c;		
	}
	for (j = 0; j < i; ++j)
		cout << P[A[j]] << "\n";
	return 0;
}

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

int const M=1000010;
int a,hantei[M];

int main(){
  hantei[0]=hantei[1]=1;
  for(int i=2;i<M;i++){
    if(hantei[i]==0){
      for(int j=2;j*i<M;j++){
	if(j*i<M){
	  hantei[j*i]=1;
	}
      }
    }
  }
  for(;cin>>a;){
    int count=0;
    for(int i=0;i<=a;i++){
      if(hantei[i]==0){
	count++;
      }
    }
    cout<<count<<endl;
  }
}

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

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

int main() {
	int n;
	while (cin >> n) {
		int num = 0;
		for (int i = 1; i <= n; i++) {
			if (i <= 3) {
				if (i == 2 || i == 3) num++;
				continue;
			}
			else {
				if (i % 2 == 0 || i % 3 == 0) continue;
				if (i % 6 != 1 && i % 6 != 5) continue;
				bool check = true;
				for (int j = 5; j < i; j += 2) {
					if (i % j == 0) {
						check = false;
						break;
					}
				}
				if (check == true) num++;
			}
		}
		cout << num << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
int isprime(int x){
    int a[x],b=0;
    for(int i=0;i<x;i++){
        a[i]=i+1;
    }
    for(int i=0;i<x;i++){
        if(a[i]==2||a[i]==3) b++;
        if(a[i]<5||a[i]%2==0||a[i]%3==0)goto exit;
    else{
        int j=5;
        while(j<sqrt(x)){
            if(a[i]%j==0)goto exit;
            j = j+2;
        }
        b++;
    }
    exit:;
}
    return b;
}
int main() {
    int n;
    while(cin >> n){
        cout << isprime(n) << endl;
        }
    }

C++: #include<iostream>
using namespace std;
int main(){
    int X,ans,count;
    bool num[1000001]={};
    for(int i=2;i<=1000000;i++){
        if(!num[i]) 
        for(int j=i*2;j<=1000000;j+=i)  num[j] = true;
    }
    while(cin >> X)
    {
        count = 0;
        for(int i=2;i<=X;i++){
            if(!num[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define MAX 1000000
using namespace std;

int main(){

  vector<int> prime(MAX,1);
  vector<int> ans;
  
  prime[0] = 0;
  prime[1] = 0;
  prime[2] = 1;
	
  for(int i=4;i<MAX;i+=2)
	prime[i] = 0;
	
  for(int i=3;i<sqrt(MAX);i+=2)
	for(int j=i+i;j<MAX;j+=i)
	  prime[j] = 0;
  
  int n;
  
  while(cin>>n){
	int cnt = 0;
	for(int i=0;i<=n;++i)
	  if(prime[i]==1)
		cnt++;
	cout<<cnt<<endl;
  }
	
  return 0;
  
}

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

#define M 1000001

int main(void)
{
    int x, i, j;
    int p[M];
    
    for (i = 0; i < M; i++) {
        p[i] = 1;
    }
    p[0] = p[1] = 0;
    for (i = 2; i * i < M; i++) {
        if (p[i] == 1) {
            for (j = i * i; j < M; j += i) {
                p[j] = 0; 
            }
        }
    } 
    for (i = 0; i < M-1; i++) {
        p[i+1] += p[i];
    }
    while (scanf("%d", &x) != EOF) {
        printf("%d\n", p[x]);
    } 
    return (0);
}

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

int main()
{
	int n[30];
	int i = 0;
	while(cin >> n[i]) {i++;}
		
	for (int k = 0;k < i;k++){
		int s = 0;
		for (int j = 2;j <= n[k];j++){
			int yaku = 0;
			for (int m = 1;m <= j / 2;m++){
				if (j % m == 0){yaku++;}
			}
			if (yaku == 1){s++;}
		}
		cout << s << endl;
	}	
    return 0;
}