Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n % i == 0 {
			return false
		}
	}
	return true
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

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

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool isprime (int n){

	if (n == 0 || n == 1){
		return false;
	}else if (n == 2){
		return true;
	}else if (n % 2 == 0){
		return false;
	} // end if
	
	for (int i = 3; i <= sqrt(n); i+= 2){
		if (n % i == 0){
			return false;
		} // end if
	} // end for
		
	return true;
}

int main()
{
	
//	cut here before submit 
//	freopen("testcase.prime", "r", stdin);
	string str = "";
	vector <int> prime(1000000, 0);

	int count = 0;
	for (int i = 2; i < 1000000; ++i){
		if (isprime(i)){
			++count;
		} // end if
		prime[i] = count;
	} // end for	

	while (getline (cin, str )){
		int n = 0;
		stringstream ssn(str);
		ssn >> n;
		cout << prime[n] << endl; 
	} // end while

	return 0;
}

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

int main()
{
    int prime[MAX-1], S[MAX-1];
    for (int i = 0; i < MAX; i++)
    {
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for (int i = 2; i < MAX; i++)
    {
        if (prime[i] != 0)
        {
            for (int j = 2 * i; j < MAX; j += i)
            {
                prime[j] = 0;
            } } }
        
        
    for (int i = 1; i < MAX; i++)
    {
        S[i] = prime[i] + S[i - 1];
    }
    S[0] = prime[0];
    int N;
    while (cin >> N)
    {
        cout << S[N] << endl;
    }
    return 0;
}