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<algorithm>
#include<cstdio>
using namespace std;

int main(){
int unti[100002] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
	if((a * n  ) < 100001 ) unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt ;
	}


}

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

const int maxn=1e6+10;
bool prime[maxn];
int sum[maxn];

void isprime()
{
    memset(prime,true,sizeof(prime));
    for(int i=2;i<=1e3;i++)
    {
        if(prime[i])
        {
            for(int j=i*i;j<1e6;j+=i)
                prime[j]=false;
        }
    }
}

void add()
{
    memset(sum,0,sizeof(sum));
    for(int i=2;i<maxn;i++)
    {
        sum[i]=sum[i-1];
        if(prime[i])
            sum[i]++;
    }
}

int main()
{
    int n;
    isprime();
    add();
    while(scanf("%d",&n)!=EOF)
        printf("%d\n",sum[n]);
    return 0;
}

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

int count_prime( unsigned int const& n )
{
    if ( n <= 0 || 1000000 <= n ) return -1;
    std::vector<bool> memo_prime( n+1, true );
    for ( unsigned int i = 2; i < n; ++i )
    {
        for ( unsigned int j = 2; i*j <= n; ++j )
        {
            memo_prime.at(i*j) = false;
        }
    }
    memo_prime.at(0) = memo_prime.at(1) = false;
    memo_prime.at(2) = true;
    return std::count( memo_prime.begin(), memo_prime.end(), true );
}

int main()
{
    int n;
    while( std::cin >> n )
    {
        std::cout << count_prime(n) << std::endl;
    }
    return 0;
}

C++: #include <stdio.h>

int check_prime(int a)
{
   int c;

   for ( c = 2 ; c <= a-1; c++ )
   {
      if ( a%c == 0 )
        return 0;
   }
      return 1;
}

int main ()
{
    int  n=0,i=0,prime=0,result=0;

   while( scanf("%d",&n) != EOF)
{
 for(i=2;i<=n;i++)
 {

   result = check_prime(i);

   if ( result == 1 )
     prime = prime +1;
 }
 printf("%d",prime);
 printf("\n");
 prime=0;
}
 return 0;
}

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

int MAX = 1000001;
int prime[1000001] = {};

void make_prime(){
  int i, j;

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

  for (i = 2; i * i < MAX; i++) {
    if (prime[i]){
      for (j = i * 2; j < MAX; j += i) {
        prime[j] = 0;
      }
    }
  }
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  make_prime();
  int i, input, count;

  while (cin >> input) {
    count = 0;
    for (i = 0; i <= input; i++) {
      if (prime[i] == 1) { count += 1; }
    }
    cout << count << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
//#include<time.h>
using namespace std;

int main()
{
	
	long long int k,p[100000];
	long long int n;
	//time_t time1,time2;
	p[0]=2;
	while(cin>>n){
		//time(&time1);
		if(n<0){
			break;
		}
	k=0;
	int r=(int)sqrt((float)n);
	for(int i=3;i<=r;i++){
		for(int j=0;j<k+1;j++){
			if(i%p[j]==0){
				break;
			}else if(j==k){
				k++;
				//cout<<i<<endl;
				p[k]=i;
			}
		}
	}
	long long int r_k=k;
	for(;r<n;r++){
		for(long int i=0;i<=r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==r_k){
				k++;
				//cout<<r<<endl;
			}
		}
	}
	//time(&time2);
	if(k!=0&&k!=1){
		k+=1;
		cout<<k<</*"ツ古t\t"<<difftime(time2,time1)<<"minutes"<<*/endl;
	}else{
		cout<<k<</*"\t\t"<<difftime(time2,time1)<<"minutes"<<*/endl;
	}
	}
}

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

int p[1000000],size;

bool isPrime(int x){
	for(int i=0;p[i]*p[i]<=x;i++){
		if(x % p[i] == 0) return false;
	}
	return true;
}

void mkPrime(int n){
	size = 0;
	p[size++] = 2;
	for(int i=3;i<=n;i+=2){
		if(isPrime(i)){
			p[size++] = i;
		}
	}
}


int main(void){
	mkPrime(1000020);

	int n;	
	while(cin>>n){
		int ans = 0;
		for(int i=0;p[i]<=n;i++){
			ans++;
		}
		printf("%d\n",ans);
	}

	return 0;
}

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

int main() {
  int n;
  bool is_prime[1000000];
  int count;

  while (1) {
    cin >> n;
    if (cin.eof()) break;
    for (int i=2; i<=n; i++) is_prime[i] = true;

    for (int i=2; i*i<=n; i++) {
      if (is_prime[i]) {
        for (int j=i+i; j<=n; j+=i) {
          is_prime[j] = false;
        }
      }
    }

    count = 0;
    for (int i=2; i<=n; i++) {
      if (is_prime[i]) count++;
    }

    cout << count << endl;
  }

  return 0;
}

C++: #include<cstdio>
#include<cstring>

const int N = 19;
int dp[N];
int isprime[N];

int main()
{
    dp[1] = 0;
    for(int i=2;i<N;i++)
    {
        if(!isprime[i])
            for(int j=2*i;j<N;j+=i)
                isprime[j] = 1;
        dp[i] = dp[i-1] + ((isprime[i])?0:1);
    }

    int y;
    while(~scanf("%d",&y))
        printf("%d\n",dp[y]);
    return 0;
}

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

using namespace std;

bool is_prime(const unsigned n);


int main(){
	int n;

	while(cin >> n){
		int ans=0;

		for(int number=2;number<=n;number++){
			if(is_prime(number))ans++;
		}
		printf("%d\n",ans);
	}


	return 0;
}

bool is_prime(const unsigned n){
	if(n == 2)return true;

    if(n%2 == 0) return false;

    for(unsigned i=3;i*i<=n;i+=2){
        if(n%i == 0) return false;
    }

    return true;
}

C++: 
#include<iostream>
#define N 1000000


using namespace std;
void PrimeNum(int n,bool Primeif[]){
  for(int i = 2;i*i <= n;i++){
    if(Primeif[i] == true){
      for(int k = 2;k * i <= n;k++){
	Primeif[k*i] = false;
}
    }
  }
}
int main(){
  int n,num;
  bool Primeif[N+1];
  Primeif[1] = false;
  for(int i = 2;i < N;i++){
    Primeif[i] = true;
  }
  PrimeNum(N+1,Primeif);
  
  while(cin >> n){
    num = 0;
    for(int i = 0;i < n;i++){
      if(Primeif[i] == true){
	num = num+1;
      }
    }
     cout << num << endl;
     
   } 
    
}