Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include<iostream>
#include<math.h>

using namespace std;

int A[1000000];
int Eratosthenes(int n)
{
	int mama = 0;
	for (int i = 0; i < n; i++)
	{
		A[i] = 1;
	}
	for (int i = 2; i < sqrt(n); i++)
	{
		if (A[i])
		{
			for (int j = 0; i*(j + 2) < n; j++)
			{
				A[i*(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < n; i++)
	{
		if (A[i])
		{
			mama++;
		}
	}
	return mama;
}

int main()
{
	int n;
	cin >> n;
	while (n != -1)
	{
		cout << Eratosthenes(n) << endl;
		cin >> n;
	}
	return 0;
}

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

int main(){
  bool prime[1000000];
  prime[0]=false;prime[1]=false;
  for(int i=2;i<=999999;i++){
    prime[i]=true;
  }

  for(int i=2;i<=sqrt(999999);i++){
    if(prime[i]){
      for(int j=2;j*i<=999999;j++){
        prime[j*i]=false;
      }
    }
  }
  int n;
  while(cin>>n){
    int cnt=0;
    for(int i=2;i<=n;i++){
      if(prime[i])cnt++;
    }
    cout<<cnt<<endl;
  }
}

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

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it)

const int limit = 1000000;
std::vector<int> q;

int main(){
    q.push_back(2);
    for(int i = 3; i < limit; i += 2){
        bool f = true;
        FOREACH(it, q){
            int p = *it;
            if(i < p*p) break;
            if(i % p == 0){ f = false; break; }
        }
        if(f) q.push_back(i);
    }
    int n;
    while(std::cin >> n){
        int l = 0, r = q.size()-1, c = -1;
        while(l <= r){
            c = (l + r)/2;
            if(q[c] < n){ l = c + 1; continue; }
            if(q[c] > n){ r = c - 1; continue; }
            break;
        }
        if(l > r) c = r;
        std::cout << c + 1 << std::endl;
    }
}

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

int main(){
	char data[999999];
	
	int i,j,num,check,count = 0;
	
	data[0] = 0;
	data[1] = 1;
	
	for(i=3;i<1000000;i++){
		check = 1;
		if(i%2==0){
			data[i-1]=0;
		}
		if(i%2==1){
			for(j=3;j*j<=i;j+=2){
				if(i%j==0){
					check = 0;
					break;
				}
			}
			if(check == 1){
				data[i-1] = 1;
			}
			else{
				data[i-1] = 0;
			}
		}
	}
	/*
	for(i=0;i<20;i++){
		if(data[i] == 1){
			printf("%d\n",i+1);
		}
	}
	*/
	
	
	while(cin>>num){
		count = 0;
		for(i=0;i<num;i++){
			if(data[i] == 1){
				count++;
			}
		}
		printf("%d\n",count);
	}
	
	
	
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define SIZE 1000000
int main(){
	vector<bool>bo(SIZE,false);
	for(int i=2;i<SIZE;i++){
		if(bo[i]==false){
			for(int j=i*2;j<SIZE;j+=i){
				bo[j]=true;
			}
		}
	}
	vector<int>ans(SIZE);

	for(int i=2;i<SIZE;i++){
		if(bo[i]==false){
			ans[i]=ans[i-1]+1;
		}
		else {
			ans[i]=ans[i-1];
		}
	}
	int n;
	while(cin>>n){
		cout<<ans[n]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;
#define MAX 1000000
#define LMT 1000
int sieve();
int calculation();
unsigned flag[MAX>>6];

int primes[5761455];
#define ifc(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define isc(n) (flag[n>>6]|=(1<<((n>>1)&31)))
int main()
{
    sieve();
    return 0;
}

int sieve()
{
    unsigned i, j, k;
    for(i=3; i<LMT; i+=2)
        if(!ifc(i))
            for(j=i*i, k=i<<1; j<MAX; j+=k)
                isc(j);
    calculation();
    return 0;
}

int calculation()
{
    unsigned int i;
    int k = 1;
    primes[0] = 2;
    for( i=3; i<MAX; i+=2)
    {
        if(ifc(i)==0)
            primes[k++] = i;
    }
    int input;
    int count;
    while(scanf("%d",&input)==1)
    {
        count=0;
        for(i=0; primes[i]<=input; i++)
            count++;
        printf("%d\n",count);
    }
    return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int count;
	c[0]=c[1]=0;
	for(i=2;i<100000;i++){
		c[i]=1;
	}

	while((scanf("%d",&n)!=EOF)&&(n!=0)){

		count=0;

		
		for(i=2;i<=n;i++){
			if(c[i]==1){
				for(j=i+1;j<=n;j++){
					if(j%i==0){
						c[j]=0;
					}
				}
				count++;
			}
		}

		printf("%d",count);


	}





	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include<string>
#include<vector>
int main() {
	int n;
	while (std::cin >> n)
	{
		std::vector<bool> v(n + 1 ,false);
		int c = 0;
		v[0] = true, v[1] = true;
		for (int i = 2; i * i <= n ; ++i) {
			if (!v[i]) {
				for (int j = i * i; j <= n; j += i) {
					v[j] = true;
					++c;
				}
			}
		}

		std::cout << n-c-1 << std::endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = (1e8);
bool p[MAX];
short num[MAX];
void isPrime(){
  rep(i,MAX)p[i] = true;
  p[0] = p[1] = false;
  num[0] = num[1] = 0;
  loop(i,2,MAX){
    num[i] = num[i-1] + p[i];
    if(p[i]){
      for(int j = i + i ; j < MAX ; j += i){
	p[j] = false;
      }
    }
  }
}

int main(void){
  isPrime();
  int n;
  while(cin>>n)cout<<num[n]<<endl;
  
  return 0;
}

C++: #include <stdio.h>

int main(){
	int sosuu[100000] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	
	while (scanf("%d", &n)!=EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

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

void Sieve(int n)
{
	bool prime[n+1];
	int c=0;
	memset(prime, true, sizeof(prime));

	for (int p=2; p<=n; p++)
	{
		if (prime[p] == true)
		{
			for (int i=p*2; i<=n; i += p)
				prime[i] = false;
		}
	}
	for (int p=2; p<=n; p++)
	if (prime[p])
		c++;
		cout<<c<<endl;
}

int main()
{
	int n;
	while(cin>>n){
        Sieve(n);
	}

	return 0;
}

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

int main() {
	int n;

	while (std::cin >> n) {
		std::vector<int> nums;
		++n;
		for (int i = 0; i < n; ++i) {
			nums.push_back(i);
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) < 2) continue;
			for (int j = nums.at(i) * 2; j < n; j += nums.at(i)) {
				nums.at(j) = 0;
			}
		}
		std::cout << std::count_if(nums.begin(), nums.end(), [](auto const& n) { return n > 1; }) << std::endl;
	}
	return 0;
}

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

int main(){
  int a;
  int i, j;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt((double)a);
      for(i=2; i<=a_sqrt; i++){
        for(j=past+1; j<=a; j++){
          if(j%i==0) chk[j]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}