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 <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 = (long int)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] == true) count++;
		}
		std::cout << count << std::endl;
		if (c == EOF) break;
	}
	return 0;
}

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

C++: #include<iostream>
#include<cstdio>
#include<cstring>
int cnt,n,prime[1000000];
using namespace std;

void getprime()
{
	/*int tt=0,flag;
	prime[tt++]=2;
	for(int i=3;i<=1000000;i++) 
	{
		flag=1;
		for(int j=0;prime[j]*prime[j]<=i;j++)
		{
			if(i%prime[j]==0)
			{	
			    flag=0;
		     	break;
			}
		}
		if(flag==1) prime[tt++]=i;
	}*/
	memset(prime,0,sizeof(prime));  
    for(int i = 2; i<=1000000; i++)  
    {  
        if (!prime[i]) prime[++prime[0]] = i;  
        for(int j = 1;j<=prime[0] &&prime[j] < 1000000/i;j++ )  
        {  
            prime[prime[j]*i] = 1;  
            if(i%prime[j]==0) break;  
        }  
    } 
}

int main()
{	getprime();
	while(scanf("%d",&n))
	{
       for(int i=1;;i++){
       	if(prime[i]>n){
       		printf("%d\n",i-1);
       		break; 
		   }
	   }
    }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(){
	int i,j,n;
	static bool prime[1000001];
	for (i = 3; i <= 1000000; i += 2){
		prime[i] = true;
	}
	prime[2] = true;

	for (i = 3; i <= 1000; i += 2){
		if (prime[i] == 1){
			for (j = 3; j <= 1000000 / i; j += 2){
				prime[i * j] = false;
			}
		}
	}
	while(cin >> n && n){
		int count = 0;
		for(i=2;i<=n;i++){
			if(prime[i] == true) count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <stdint.h>
using namespace std;

int sieve(int x)
{
  int ret = 0;
  vector<bool> v(x + 1, true);
  for (int i = 2; i <= x; i++) {
    if (v[i]) {
      ret++;
      for (int j = i + i; j <= x; j += i) {
        v[j] = false;
      }
    }
  }

  return ret;
}

int main()
{
  for (int n; cin >> n; ) {
    cout << sieve(n) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
bool isPrime(long a) {
	if (a < 2) return false;
	long i;
	for (i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
signed main() {
	int Prime[1000000] = {};
	for (int i = 0; i < 1000000; i++) {
		if (isPrime(i)) {
			Prime[i] = 1;
		}
	}
	for (int i = 1; i < 1000000; i++) {
		Prime[i] += Prime[i - 1];
	}
	int n;
	while (cin >> n) {
		cout << Prime[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int tim(int n)
{
	int i,s=0;
	int *a;
	a=new int [n+1];
	for(i=1;i<=n;i++)
	a[i]=1;
	for(i=2;i*i<=n;i++)
	{
		if(a[i]!=0)
		for(int j=i*i;j<=n;j=j+i)
		a[j]=0;
	}
	for(i=2;i<=n;i++)
	if(a[i]==1)
	{
	s=s+1;
   } 
	return s;
}
int main()
{
	int n,i=1;
	do
	{
		int k;
		cin>>n;
		if(n<2)
		k=0;
		else
		k=tim(n);
		cout<<k;
		cout<<endl;
	}
	while(1);
}

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

using namespace std;


void initialize(vector<int> &search_list, int num);

void era(vector<int> &search_list, vector<int> &prime_list, int num);


int main(int argc, char* argv[]){

  int num;

  while (cin >> num){
    vector<int> search_list, prime_list;
    initialize(search_list, num);
    era(search_list, prime_list, num);
    cout << prime_list.size() << endl;
  }
  return 0;
}

void initialize(vector<int> &search_list, int num){
  for (int i=2; i<=num; ++i){
    search_list.push_back(i);
  }
  return;
}

void era(vector<int> &search_list, vector<int> &prime_list, int num){
  do{
    vector<int>::iterator it = search_list.begin();
    int count = 1;
    int N = *it;
    prime_list.push_back(*it);
    while ((N*count) <= num){
      it = find(search_list.begin(), search_list.end(), (N*count));
      if (it != search_list.end()){
        it = search_list.erase(it);
      }
      ++count;
    }
  } while (!search_list.empty());
}

C++: 
#include<stdio.h>
int main()
{
    int a,N,M,sum=0,i,j,count=0,flag=0;
    while (scanf ("%d",&M)!=EOF )
        {
            for(i=2;i<=M;i++)
            {
                flag=0;

                if(i>2)
                {
                    for(j=2;j<i;j++)
                    {
                        if(i%j==0)
                        {
                            flag=1;
                            break;
                        }
                    }
                }
                    if(flag==0)
                    {
                        count++;

                    }


            }
                  printf("%d\n",count);
                  count=0;
        }

    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool F[1000000]={};


int main(){

	for(int i=2;i<1000000;i++)
	for(int j=2;j*j<=i;j++){
		if(i%j==0){F[i]=false;break;}
		else F[i]=true;
	}
	F[2]=true;F[3]=true;
	int N;
	while(cin>>N){
		int c=0;
		for(int i=0;i<=N;i++){
			if(F[i]==true){c++;//cout<<i<<endl;
			}}

		cout<<c<<endl;
	}
	return 0;

}

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

int main(){
  
  int n,cnt = 0;

  while(cin >> n){
    int num[n] = {};
    for(int i = 2; i  <= n; i++){
      if(num[i] == 0){
        for(int j = 1; j <(n/i); j++){
          num[i+(j*i)] = 1;
        }
        cnt++;
      }
    }
  cout << cnt << endl;
  }
}

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

int main(){
	int n;
	int count;
	int ans;

	while (cin >> n){
		ans = 0;
		for (int i = 2; i <= n; i++){
			count = 0;
			for (int j = 2; j < i; j++){
				if (i % j == 0){
					count++;
				}
			}
			if (count == 0)ans++;
		}
		cout << ans << endl;

	}


	return 0;
}