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<cstdio>
#include<cmath>
using namespace std;
int main(){
  long long int a[1000000]={0};
  a[1]=1;
  for(int i=2;i<sqrt(1000000);i++){
    for(int j=2;j<sqrt(1000000);j++){     
      a[i*j]=1;
    }
  }
  int n;
  int cont;
  while(scanf("%d",&n)!=EOF){
    cont=0;
    for(int i=1;i<=n;i++){
      if(a[i]==0)cont++;
    }
    cout<<cont<<endl;
  }
}

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

const int size=1000000;
vector<int> map(size,1);
void sieve(int p)
{
    for(int j=p*2;j<size;j+=p)
    {
        map[j]=0;
    }
}
int main(void)
{
    map[0]=0;
    map[1]=0;
    sieve(2);
    sieve(3);
    sieve(5);
    for(int i=7;i<1000;i+=6)
    {
        sieve(i);
        sieve(i+4);
    }

    while(1)
    {
        int n;
        int num=scanf("%d",&n);
        if(num != 1)
            break;
        printf("%d\n",count(map.begin(),map.begin()+n+1,1));
    }
    return 0;
}

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


vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main()
{
	int n;
	while(cin>>n){
		vector<int> V=sieve_of_eratosthenes(n+1);
		V.erase(remove(V.begin(),V.end(),0),V.end());
		cout<<V.size()<<endl;
	}
	return 0;
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;
typedef long long int ll;

int main(){
    vector<int> era(10000000,0);
    for (int i=1; i<era.size(); i++) {
        era[i]=1;
    }
    for (int i=2; i<era.size(); i++) {
        if (era[i]!=0) {
            int q = i + i;
            while (q<era.size()) {
                era[q]=0;
                q += i;
            }
        }
    }
    int n;
    while (cin >> n) {
        int ans=-1;
        for (int i=1; i<=n; i++) {
            if (era[i]) {
                ans++;
            }
        }
        cout << ans <<endl;
    }
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i;
	if(x == 2){
 		return 1;
	}
  	if(x<2||x%2==0){
		return 0;
	}
	i = 3;
	while( i <= sqrt(x) ){
		if(x%i==0){
			return 0;
		}
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=0;
		for(int i=0;i<=n;i++){
			if(isprime(i)){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

C++: 
#include<stdio.h>
#include<string.h>
#define range 999999
int total_added = 4;
struct primes{
	 int  key;
	 int  counts;
};
primes p[range];
bool is_prime(int key)
{
	int i;
	for (i = 2; i <= sqrt(key); i++)
	{
		if (key%i == 0)return false;
	}
	return true;
}
void init()
{
	p[0].key = 2;
	p[0].counts = 1;
	p[1].key = 3;
	p[1].counts = 2;
	p[2].key = 5;
	p[2].counts = 3;
	p[3].key = 7;
	p[3].counts = 4;
	int i;
	for (i = 8; i <= range; i++)
	{
		if (i % 2 != 0&&i%3!=0&&i%5!=0)
		{
			if (is_prime(i))
			{
				p[total_added].key = i;
				p[total_added].counts = p[total_added - 1].counts + 1;
				total_added++;
			}
		}
	}
}
int counting_result(int key)
{
	for (int i =total_added-1; i>=0; i--)
	{
		if (key >= p[i].key)
			return p[i].counts;
	}
	return 0;
}

int main()
{
	init();
	int i=0, n;
	while (i<30)
	{
		scanf("%d", &n);
		printf("%d\n",counting_result(n));
		i++;
	}

}

C++: #include<iostream>
#define N 1000001
using namespace std;
int main(){
  int n;
  int p[N]={0};
  for(int i=3;i<=N;i+=2) p[i] = 1;
  p[2] = 1;
  for(int i=3;i<=1000;i+=2){
    if(p[i]==1){
      for(int j=2*i;j<=N;j+=i) p[j] = 0;
    }
  }
  while(cin>>n){
    int count = 0;
    if(2<=n) count++;
    for(int i=3;i<=n;i+=2){
      if(p[i]) count++;
    }
    cout << count << endl;
  }
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	while (cin >> n){
		int cnt=0;
		for (int i=2; i<=n; ++i){
			bool op=false;
			for (int j=2; j<=sqrt(i); ++j){
				if (i%j == 0){
					op = true;
					break;
				}
			}
			if (op == false) ++cnt;
		}
		cout << cnt << '\n';
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n;

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

        int ans = 1;
        for (int i = 3; i <= n; i += 2) {
            bool flag = true;
            
            if (!(i % 2))
                continue;
            for (int j = 3; j * j <= i; j += 2) {
                if (!(i % j)) {
                    flag = false;
                    break;
                }
            }
            if (flag)
                ans++;
        }
        cout << ans << endl;
    }
    
    return 0;
}

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

using namespace std;

vector<bool> prime(1000010, 1);
int n;

void precalc()
{
    prime[0] = 0; prime[1] = 0; prime[2] = 1;
    for( int i = 2; i * i <= 999999; i++ ){
        if( prime[i] ){
            for( int j = 1; ( j + 1 ) * i <= 999999; j++ ){
                prime[i * ( j + 1 )] = 0;
            }
        }
    }

}

signed main(){
    precalc();
    while( scanf( "%d", &n ) != EOF )
    {
        int ret = 0;
        for( int i = 0; i <= n; i++ )
        {
            if( prime[i] )
            {
                ret++;
            }
        }
        printf( "%d\n", ret );
    }
    return 0;
}