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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

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

#define MAX 1000000
#define NIL -1

int primes[MAX];

bool isPrime(int n)
{
    if (n <= 1) {
        primes[n] = 0;
        return false;
    }
    if (n <= 3) {
        primes[n] = 1;
        return true;
    }
    if (n % 2 == 0 || n % 3 == 0) {
        primes[n] = 0;
        return false;
    }
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0) {
            primes[n] = 0;
            return false;
    }
    primes[n] = 1;
    return true;
}

int main()
{
    for (int i = 1; i <= MAX; i++) primes[i] = NIL;
    int N, sum;
    while(std::scanf("%d", &N) != EOF) {
        sum = 0;
        for (int i = 2; i <= N; i++) {
            if (primes[i] != NIL) {
                if (primes[i] == 1) sum++;
            }
            else {
                if (isPrime(i)) sum++;
            }
        }
        std::printf("%d\n", sum);
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define llint long long
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int pn = 0;
int p[1000000];
void getsosu(int Max) {
    for(int i = 2; i <= Max; i++) {
        bool flg = true;
        for(int j = 0; j < pn; j++) {
            if(p[j] * p[j] > i) break;
            if(i % p[j] == 0) {
                flg = false;
                break;
            }
        }
        if(flg) p[pn++] = i;
    }
}

int main() {
    getsosu(999999);

    int n;
    while(cin >> n) {
        int i = 0;
        while(p[i] <= n) i++;
        cout << i << endl;
    }
    return 0;
}

C++: <?php
$max=1000000;
$maxR=floor(sqrt($max));

$ch=[0,0,1,1];

for($i=4;$i<$max;$i+=2){$ch[]=0;$ch[]=1;}

for($i=3;$i<$maxR;$i+=2) if($ch[$i]) for($j=$i+$i;$j<$max;$j+=$i) $ch[$j]=0;

for($i=3;$i<$max;$i++) $ch[$i]+=$ch[$i-1];

while(fscanf(STDIN,"%d",$n)) printf("%d\n",$ch[$n]);

C++: #include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main(){
	int max = 1000000;
	bool is_prime[max] = {};
	for (int i = 2; i < max; ++i) {
		is_prime[i] = 1;
	}
	for (int i = 0; i < max; ++i) {
		if (is_prime[i]) {
			for (int j = i; j < max; j += i) {
				is_prime[j] = 0;
			}
		}
	}
	int num_prime[max] = {};
	for (int i = 1; i < max; ++i) {
		num_prime[i] = num_prime[i-1] + is_prime[i];
	}
	int n;
	while (cin >> n) {
		cout << num_prime[n] << endl;
	}
	return 0;
}

C++: 
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>

using namespace std;

int prime[999999];
bool is_prime[1000000];

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

int main(){

int n;

while(cin>>n){
  cout<<sieve(n)<<endl;
}

}

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

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 0;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 0;
		
		for (int i = 1;i<=num;i++) {
		if(i%2==0) {
			//cout <<"2: "<<i<<endl;
			count ++;
			continue;
		}
		for (int j=3;j<(int)sqrt(i)+1;j=j+2) {
			if (i%j==0) {
				count ++;
				//cout <<"i: "<<i<<" j: "<<j<<endl;
				break;
			}
		}
	}
	cout << (num-count) <<endl;
	//cout << endl;
	}
	return 0;
}

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

int main(){
	int n, temp, counter;
	temp = 0;
	counter= 0;
	while(cin >> n){
		vector<int> num(n);
		num[0], num[1] = 1;
		for(int i = 0; i < n; i++){
			if(num[i] == 0){
				for(int j = 0; temp < n; j++){
					temp = i * j;
					num[temp] = 1;
					counter++;
				}
			}
		}
		cout << counter << endl;
	}
	return(0);
}

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

int main()
{
  int n;
  while(cin >> n){
    double nd=(double)n;
    int root=(int)sqrt(nd);
    int count=0;
    for(int i=2;i<=n;i++){
      int j;
      for(j=2;j<=root;j++){
        if(i%j==0) break;
      }
      if(j==root) count++;
    }
    cout << count << endl;
  }
  
  return 0;
}

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;
	cout << Eratosthenes(n) << endl;
	return 0;
}

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

int main(void) {
    int N=999999;
    int p[N] , s[N];
    p[0]=0;
    for (int i=1; i<N; i++){
        p[i] = 1;
        s[i] = 0;
    }
    for (int i=1; i<N; i++){
        cout << i;
        if (p[i]==1){
            int n=i+1 , m=2*n;
            while (m<=N){
                p[m-1] = 0;
                m += n;
            }
        }
    }
    
    for (int i=1; i<N; i++){
        s[i] = s[i-1]+p[i];
    }
    int n;
    while (1){
        cin >> n;
        cout << s[n-1] << endl;
    }
    return 0;
}