Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  bitset<1'000'000> bs;
  bs.set();
  bs[0] = bs[1] = false;
  for (int p = 2; p <= 1000; ++p) {
    for (int i = p * p; i < 1'000'000; i += p) bs[i] = false;
  }
  string s;
  while (getline(cin, s)) {
    int n = stoi(s);
    int res = 0;
    for (int i = 0; i <= n; ++i) res += bs[i];
    cout << res << '\n';
  }
}

C++: #include <cstdio>
#define max_n 999999
int prime[max_n];
bool is_prime[max_n+1];
int main(){
    for(int i=0; i<max_n; i++){
        is_prime[i]=true;
    }
    int p = 0;
    is_prime[1]=false;
    is_prime[0]=false;
    for(int i=2;i<max_n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i;j<max_n;j+=i)is_prime[j]=false;
        }
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",n);
        int ans = 0;
        for(int i =0; i<max_n; i++){
            ans = 0;
            if(prime[i]>n){
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

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

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

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

int Eratosthenes(int N){

  int count=0;
  bool* IsPrime = new bool[N];
  IsPrime[0] = false;
  IsPrime[1] = false;
  for(int i=2; i<=N;i++){
    IsPrime[i] = true;
  }
  for(int i=2; i*i<=N;i++){
    if(IsPrime[i]){
      for(int j=2*i; j<=N; j+=i)
        IsPrime[j] = false;
      }
  }
  for(int i=0; i<=N;i++)
    if(IsPrime[i]) count++;

  delete[] IsPrime;
  return count;
}

int main(void)
{
    int N[30]={};
    int count=0;
    int i=0;
    while(1){
      if(scanf("%d",&N[i])!=1)
        break;
      i++;
    }
    i=0;
    while(N[i]>0){
      count=Eratosthenes(N[i]);
      printf("%d\n",count);
      i++;
    }

    return 0;
}

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

bool Prime(int n);

int main(){

  int n;
  int sum;

  while(scanf("%d",&n)!=EOF){
    sum = 0;
    for(int i=3; i<=n; i+=2){
      sum += Prime(i);
    } 
    cout << sum+1 << endl;
  }

  return 0;
}


bool Prime(int n){

  if(n%2==0)
    return false;

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

  return true;
}

C++: #include<stdio.h>
#include<math.h>
int gurobal[1000001]={0};
int main(void)
{
	int n=0;
	int i=0,j=0;
	int heihoukon=0;
	int count=0;
	while(scanf("%d",&n)!=EOF)
	{
		count=0;
		gurobal[1]=0;
		for (i=2;i<=n;i++)
		{
			gurobal[i]=1;
		}
		(int)heihoukon=sqrt((double)n);
		for (i=2;i<=heihoukon;i++)
		{
			if (gurobal[i]!=0)
			{
				for (j=i*2;j<=n;j+=i)
				{
					gurobal[j]=0;
				}
			}
		}
		for (i=2;i<=n;i++)
		{
			if (gurobal[i]!=0)
			{
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

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

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

#define MAX_NUM (1000000)

static int getPrimeNum(int maxVal);

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

static int getPrimeNum(int maxVal)
{
  static int searchList[MAX_NUM] = {0};
  static int primeList[MAX_NUM] = {0};
  
  double sqMaxVal = sqrt((double)maxVal) + 1;
  
  for (int i = 2; i <= sqMaxVal; i++) {
    if (searchList[i] == 0) {
      searchList[i] = 1;
      primeList[i] = 1;
      for (int j = i + 1; j <= maxVal; j++) {
        if (j % i == 0) {
          searchList[j] = 1;
        }
      }
    }
  }
  
  for (int i = 2; i <= maxVal; i++) {
    if (searchList[i] == 0) {
      primeList[i] = 1;
    }
  }
  
  int count = 0;
  for (int i = 2; i <= maxVal; i++) {
    if (primeList[i] == 1) {
      count++;
    }
  }
  
  return count;
}

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

int main()
{
	long int n,m;
	while(cin>>n){
		long int i;
		int number[100000]={0};
		int ans=0;

		for(i=2;i<n;i++){
			if(number[i]==0){
				ans++;
				for(m=i;m<n;m+=i){
					number[m]=1;
				}
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e6+5;
int is_prime[N];

int prime(int n)
{
	for(int i = 0;i <= n;++i)	
		is_prime[i] = true;
	is_prime[0] = 1;is_prime[1] = false;
	int res = 0;
	for(int i = 2;i <= n;++ i)
	{
		if(is_prime[i])
		{
			++res;
			for(int j = i * 2;j <= n;j += i)
				is_prime[j] = false;
		}
	}
	return res;
}

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