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 <iostream>
#include <iomanip>

using namespace std;


int main(int argc, const char * argv[]) {
    // insert code here...
    
    int maxNumber;
    int countPrime=0;
    bool judgePrime = true;
    
    cin >> maxNumber;
    
    for(int i=2; i<=maxNumber;i++){
        for(int j=2; j<i;j++){
            if(i%j==0){
                judgePrime = false;
            }
        }
        if(judgePrime){countPrime++;}
        judgePrime = true;
    }
    cout << countPrime;
    
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool prime(int n)
{
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int main()
{
    int c,i,p=0;
    int in[30],out[30];
    while(scanf("%d",&in[p])!=EOF)
    {
        c=0;
        for(i=2;i<=in[p];i++)
        {
            if(prime(i))
                c++;
        }
        out[p] = c;
        p++;
    }
    for(i=0;i<p;i++)
        cout<<out[i]<<endl;
    return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int a;
	int sum;
	while (cin >> a){
		sum = 0;
		for (int i = 0; i < a; i++){
			int y = 0;
			int l = i + 1;
			for (int i = 1; i != l+1; i++){
				if (l % i == 0) {
					y++;
				}
			}
			if (y == 2)sum++;
		}
		cout << sum << endl;
	}
}

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

int main(){
	const int MAX_n = 1000000;
	int n;
	bool prime[MAX_n];
	int res;
	
	for(int i = 0; i < MAX_n; i++) prime[i] = false;
	
	for(int i = 2; i < MAX_n; i++){
		if(!prime[i]){
			//printf("%d\n", i);
			for(int j = i + i; j < MAX_n; j += i){
				prime[j] = true;
				
			}
		}
	}
	
	//for(int i = 0; i < MAX_n; i++) if(prime[i]) printf("%d\n", i);
	
	while((scanf("%d", &n)) != EOF){
		res = 0;
		
		for(int i = 2; i <= n; i++){
			if(!prime[i]){ res++; }
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main(){

	vector<bool> used(1000000);
	set<ll> prime;
	
	REP(i, 2, 1000000){
		if(!used[i]) prime.insert(i);
		for(int j = 1; i * j < 1000000; j++){
			used[i*j] = true;
		}
	}
	
	int n;
	while(cin >> n){
		auto it = upper_bound(prime.begin(), prime.end(), n);
		cout << distance(prime.begin(), it) << 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 <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

bool isPrimes[1000000];

int main()
{
	int res = 0;
	int n;
	scanf("%d", &n);
	for (int i = 0; i <= n; ++i)
		isPrimes[i] = true;
	isPrimes[0] = isPrimes[1] = false;
	for (int i = 2; i <= n; ++i)
	{
		if (isPrimes[i])
		{
			for (int j = i*2; j <= n; j += i)
				isPrimes[j] = false;
			++res;
		}
	}
	printf("%d\n", res);

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;
const int maxx = 2000000;
bool is_prime[maxx];
int prime[maxx];
int a,cnt = 0;
int main()
{
    memset(is_prime,true,sizeof is_prime);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i * i < maxx; i ++ )
    {
        if(is_prime[i])
        {
            prime[cnt++]=i;
            for(int j = i*2;j < maxx; j+=i ) is_prime[j] = false;
        }
    }
    while(scanf("%d",&a)!=EOF)
    {
        int k = upper_bound(prime,prime+cnt,a) - prime;
        printf("%d\n",k);

    }

    return 0;
}

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

void sieve(int n, vector<int> &primes)
{
    vector<bool> v(n + 1, true);

    // check
    for (int i = 2, end = sqrt(n); i <= end; i++) {
        if (!v[i] || !(i & 1))
            continue;
        for (int j = i + i; j <= n; j += i)
            v[j] = false;
    }

    primes.push_back(2);
    for (int i = 3; i <= n; i += 2)
         if (v[i])
            primes.push_back(i);
}

int main()
{
    vector<int> primes;
    vector<int> inputs;
    int i;

    // read all inputs
    for (int x; cin >> x;)
        inputs.push_back(x);

    // init sieve
    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (auto x : inputs) {
        for (i = 0; i < primes.size(); i++) // find
            if (primes[i] == x) {
                i++;
                break;
            } else if (primes[i] > x)
                break;
        cout << i << endl;
    }

    return 0;
}