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<math.h>
using namespace std;
int tim(int n)
{
	int i,s=0;
	int *a;
	a=new int [n+1];
	for(i=1;i<=n;i++)
	a[i]=1;
	for(i=2;i*i<=n;i++)
	{
		if(a[i]!=0)
		for(int j=i*i;j<=n;j=j+i)
		a[j]=0;
	}
	for(i=2;i<=n;i++)
	if(a[i]==1)
	{
	s=s+1;
   } 
	return s;
}
int main()
{
	int n,i=1;
	do
	{
		int k;
		cin>>n;
		if(n<2)
		k=0;
		else
		k=tim(n);
		cout<<k;
		cout<<endl;
	}
	while(1);
}

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

using namespace std;


void initialize(vector<int> &search_list, int num);

void era(vector<int> &search_list, vector<int> &prime_list, int num);


int main(int argc, char* argv[]){

  int num;

  while (cin >> num){
    vector<int> search_list, prime_list;
    initialize(search_list, num);
    era(search_list, prime_list, num);
    cout << prime_list.size() << endl;
  }
  return 0;
}

void initialize(vector<int> &search_list, int num){
  for (int i=2; i<=num; ++i){
    search_list.push_back(i);
  }
  return;
}

void era(vector<int> &search_list, vector<int> &prime_list, int num){
  do{
    vector<int>::iterator it = search_list.begin();
    int count = 1;
    int N = *it;
    prime_list.push_back(*it);
    while ((N*count) <= num){
      it = find(search_list.begin(), search_list.end(), (N*count));
      if (it != search_list.end()){
        it = search_list.erase(it);
      }
      ++count;
    }
  } while (!search_list.empty());
}

C++: 
#include<stdio.h>
int main()
{
    int a,N,M,sum=0,i,j,count=0,flag=0;
    while (scanf ("%d",&M)!=EOF )
        {
            for(i=2;i<=M;i++)
            {
                flag=0;

                if(i>2)
                {
                    for(j=2;j<i;j++)
                    {
                        if(i%j==0)
                        {
                            flag=1;
                            break;
                        }
                    }
                }
                    if(flag==0)
                    {
                        count++;

                    }


            }
                  printf("%d\n",count);
                  count=0;
        }

    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool F[1000000]={};


int main(){

	for(int i=2;i<1000000;i++)
	for(int j=2;j*j<=i;j++){
		if(i%j==0){F[i]=false;break;}
		else F[i]=true;
	}
	F[2]=true;F[3]=true;
	int N;
	while(cin>>N){
		int c=0;
		for(int i=0;i<=N;i++){
			if(F[i]==true){c++;//cout<<i<<endl;
			}}

		cout<<c<<endl;
	}
	return 0;

}

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

int main(){
  
  int n,cnt = 0;

  while(cin >> n){
    int num[n] = {};
    for(int i = 2; i  <= n; i++){
      if(num[i] == 0){
        for(int j = 1; j <(n/i); j++){
          num[i+(j*i)] = 1;
        }
        cnt++;
      }
    }
  cout << cnt << endl;
  }
}

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

int main(){
	int n;
	int count;
	int ans;

	while (cin >> n){
		ans = 0;
		for (int i = 2; i <= n; i++){
			count = 0;
			for (int j = 2; j < i; j++){
				if (i % j == 0){
					count++;
				}
			}
			if (count == 0)ans++;
		}
		cout << ans << endl;

	}


	return 0;
}

C++: #include <stdio.h>
#define N 100000
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

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

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int i,j,c,p;

  while(cin>>n){
    c=1;
    for(i=3;i<=n;i+=2){
      p=0;
      for(j=3;j*j<=i;j+=2){
	if(i%j==0){
	  p=1;
	  break;
	}
      }
      if(p==0){
	c++;
      }
    }
    if(n==1)c=0;
    cout<<c<<endl;
  }
  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(scanf("%d", &num) != EOF){
        int count=0;
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

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

int a[999999]={};

int main(){
	int n,ans=0;
	vector<int> v;
	for(int i = 2; i*i < 999999; i++){
		for(int j = 0; j < 999999; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		for(int j = 2; j <= n; j++){
			if(a[j]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

C++: #include <cstdio>

const int size = 1000005;
int n;
bool ispm[size];

int get(int n) {
	int ans = 0;
	for ( int i = 1; i <= n; i ++ ) ispm[i] = 1;
	for ( int i = 2; i <= n; i ++ ) {
		if(ispm[i]) {
			ans ++;
			for ( int j = 2*i; j <= n; j += i) ispm[j] = 0;
		}
	}

	return ans;
}

int main() {
	while( scanf("%d", &n) != EOF ) {
		printf("%d\n", get(n));
	}

	return 0;
}

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

C++: #include<stdio.h>
#include<math.h>
int main(void) {
	int  n, sum = 0;
	while (scanf("%d", &n) != EOF) {
		int prime[1000000] = { 0 };
		prime[1] = 1;
		sum = n - 1;
		for (size_t i = 2; i <= sqrt(n); i++)
		{
			if (prime[i] == 0)
			{
				for (size_t t = i + 1; t <= n; t++)
				{
					if (t%i == 0) {
						if (prime[t] == 0)
						{
							prime[t] = 1;
							sum--;
						}
					}
				}
			}
		}
		printf("%d\n", sum);
		sum = 0;
	}
	return 0;
}