Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

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

int main() {
	const int MAX_V = 100000;
	int prime[MAX_V+1];
	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;
			}
		}
	}
	scanf("%d", &v);
	while (v != 0){
		int count = 0;
		for(i=0;i<=v;i++){
			int isprime = prime[i];
			if(isprime) count ++;
		}
		printf("%d\n",count);
		scanf("%d", &v);
	}
	return 0;
}

C++: #include<stdio.h>
	   const int MAX_V = 1000000;
	   int prime[MAX_V+1];
	   int sum[MAX_V+1];
	   int main(){
	   	int i,k,v,m=2,cnt=0;
	   	for(i=m;i<=MAX_V;i++){
	   		prime[i]=1;
	   	}
	   	for(i=m;i*i<=MAX_V;i++){
	   		if(prime[i]){
	   			for(k=2*i;k<=MAX_V;k+=i){
	   				prime[k]=0;
	   			}
	   		}
	   	}
	   	for(i=0;i<MAX_V+1;i++){
	   	 sum[i+1]=sum[i]+prime[i];
	   	}
	   	while(scanf("%d",&v)!=EOF){
	   	 printf("%d\n",sum[v+1]);
	   	}
	   	return 0;
	   }

C++: #include<stdio.h>
int prime(int x)
{
    int i,j,k,l=0;
    for(k=2;k<=x;k++)
    {
        int flag=0;
        for(i=2;i*i<=k;i++)
        {
            if(k%i==0)
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            l+=1;
        }
    }
        return l;
}

int main()
{
    int n,m;
    while(scanf("%d",&n))
    {
        m=prime(n);
        printf("%d\n",m);
    }
    return 0;
}

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)){
        int ans = 0;
        for(int i =0; i<max_n; i++){
            if(prime[i]>n){
                ans = i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <stdio.h>

const int MAX_V = 10000;
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(1){
        int count=0;
        scanf("%d", &num);
        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(void){
    int n;
    int count;
    int prime[1000000];
    int i,j;
    while(cin>>n){
        count=0;
        fill(prime,prime+1000000,0);
        prime[0]=prime[1]=1;
        for(i=2;i<=n;i++){
            if(prime[i]==0){
                count++;
                for(j=2*i;j<=n;j+=i){
                    prime[j]=1;
                }
            }
        }
        cout<<count<<endl;
    }
    return(0);
}

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

int main() {
  vector<bool> p(1000000, true);
  p[0] = false;
  p[1] = false;
  for (int i = 2; i <= 1000; i++) {
    if (p[i]) {
      for (int j = i * 2; j < 1000000; j += i) {
        p[j] = false;
      }
    }
  }

  int n;
  while (cin >> n) {
    int res = 0;
    for (int j = 0; j <= n; j++)
      if (p[j]) res++;
    cout << res << endl;
  }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int N;
    bool prime[100010]={0};
    prime[1]=1;
    for(int i=2;i*i<100000;i++){
        if(prime[i]==0){
            for(int j=i;j<100000;j+=i){
                prime[j]=1;
            }
        prime[i]=0;
        }
    }
    while(~scanf("%d",&N)){
        int cnt=0;
        for(int i=1;i<=N;i++){
            if(prime[i]==0)cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

#define MAX_SIZE (1000000)

int prime[MAX_SIZE];

int main()
{
	int n;
	
	prime[0] = prime[1] = 0;

	for (int i = 2; i < MAX_SIZE; i++){
		prime[i] = 1;
	}

	// Sieve of Eratosthenes
	for (int i = 2; i * i < MAX_SIZE; i++){
		if (prime[i]){
			for (int j = i * i; j < MAX_SIZE; j += i){
				prime[j] = 0;
			}
		}
	}

	for (int i = 1; i < MAX_SIZE; i++){
		prime[i] += prime[i - 1];
	}

	while (scanf("%d", &n) != EOF){
		printf("%d\n", prime[n]);
	}

	return (0);
}

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

int main(){
	int NUM;
	while(std::cin >> NUM){
		std::list<int> numList;
		std::list<int> primeList;
		for(int i=2;i<=NUM;++i){
			numList.push_back(i);
		}
	
		for(int i=numList.front();i<std::sqrt(NUM);i=numList.front()){
			primeList.push_back(i);
			numList.erase(std::remove_if(numList.begin(),numList.end(),[&](int num){return num%i==0;}),numList.end());
		}
		std::copy(numList.begin(),numList.end(),std::back_inserter(primeList));

		std::cout << primeList.size() << std::endl;
		}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n){
		int counter = 0;
		if(n != 1)counter++;
		for(int i = 3; i <= n; i += 2){
			for(int j = 2; j * j <= i; j++){
				if(i % j == 0)goto divisible;
			}
			counter ++;
			divisible:;
		}
		cout << counter << endl;
	}
}

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

using namespace std;

int isPrime(int a) {
    for (int i = sqrt(a) + 1; i >= 2; i--)
        if (a % i == 0)
            return 0;

    return 1;
}

int main() {

    #if 0
        ifstream cin("34870.in");
    #endif
            cout << "ok" << endl;
    int many[1000000];

    many[1] = 0;
    many[2] = 1;

    int n;
    while (cin >> n) {
        if (n == 1) {
            cout << 0 << endl;
            continue;
        }


        int i = n;
        while (many[i--] == 0);
        for (i += 1; i <= n; i++) {
            many[i] = many[i-1] + isPrime(i);
        }

        cout << many[n] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define MAX_N 1000000

using namespace std;

bool IsPrime[MAX_N];
int NofP[MAX_N];
void q9() {
	memset(IsPrime, 1, sizeof(IsPrime));
	IsPrime[0] = false;
	IsPrime[1] = false;
	for (int i = 0; i < sqrt(MAX_N); i++) {
		if (!IsPrime[i]) continue;
		for (int j = i * 2; j < MAX_N; j += i) {
			IsPrime[j] = false;
		}
	}

	
	NofP[0] = 0;
	for (int i = 1; i < MAX_N; i++) {
		NofP[i] = NofP[i - 1] + IsPrime[i];
	}

	int n;
	for (; cin >> n;) {
		cout << NofP[n] << endl;
	}
}

int main() {
	q9();
	return 0;
}