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 <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<int> v;
    v.resize(n + 1);
    fill(v.begin(), v.end(), 1);
    v[0] = 0;
    v[1] = 0;
    for (int i = 0; i * i * i * i < v.size(); ++i) {
      while (v[i] == 0) ++i;
      for (int m = i + 1; m < v.size(); ++m) {
        if (m % i == 0) {
          v[m] = 0;
        }
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}

C++: #include<stdio.h>

int main(void)
{
	int data,i,j,k=0,l=0,kai[1000]={0},s[1000000]={0};

	while(scanf("%d",&data) != EOF)
	{
		if(data<=1)
		   kai[k]=0;
		else
		{
			for(i=2;i<=data;i++)s[i]=i;

		    i=2;
			while(i*2<data)
			{
			  if(s[i] != 0)
			  {  
				 j=2;
				while(j*i<=data)
				{
					s[j*i]=0;
					j+=1;
				}
			  }
			  i+=1;
			}

			
			for(i=2;i<=data;i++)
			{	
				if(s[i]!=0)
				{
					kai[k]+=1;
				}
			}
		}
		k+=1;
	}

  for(i=0;i<k;i++)
	  printf("%d",kai[i]);

  return 0;
}

C++: #include <cstdio>
#define N 999999
unsigned char p[((N+1)/2+7)/8];
int main() {
    int i,j,s,n=3;
    for(i=0;n*n<=N;i++,n+=2)
        if(!(p[i/8]&(1<<(i%8))))
            for(j=i+n;j<((N+1)/2);j+=n)p[j/8]|=(1<<(j%8));
    while(scanf("%d",&n)!=EOF) {
        if(n<2){printf("0\n");continue;}
        if(n==2){printf("1\n");continue;}
        for(i=3,j=0,s=1;i<=n;i+=2,j++)
            s+=!(p[j/8]&(1<<(j%8)));
        printf("%d\n",s);
    }
}

C++: #include <iostream>

using namespace std;

int as[1000000];

int main(){
  int n;
  for(;;){
    cin >> n;
    if(cin.eof()) break;

    for(int i=1; i<=n; i++)
      as[i]=i;

    for(int i=2; i<=n; i++){
      if(as[i]==-1)
	continue;
      else
	for(int j=2*i; j<=n; j+=i)
	  as[j]=-1;
    }

    int cnt=0;
    for(int i=2; i<=n; i++)
      if(as[i]!=-1)
	cnt++;

    cout << cnt << endl;
  }
}

C++: #include<iostream>
using namespace std;
bool isPrime(int n){
	if(n<=1||n!=2&&(n&1)==0)return false;
	for(int i=3;i*i<=n;i+=2){
		if(n%i==0)return false;
	}
	return true;
} 
int main(){
	int n,ans;
	while(cin>>n){
		ans=0;
		for(int i=2;i<=n;i++)
			if(isPrime(i))ans++;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string> 
#include <vector> 
using namespace std;

int main(){
	int max,n[1000],c = 0,check,a;
	cin >> max;
	for(int i = 2;max >= i;i++){
		check = 0;
		for(int iii = 1;c >= iii;iii++){
			if(i % n[iii] == 0){check = 1;break;}
		}
		for(int ii = 2;i > ii and check == 0;ii++){
			if(i % ii == 0){check = 1;break;}
		}
		if(check == 0){c++;n[c] = i;}

	}
	cout << c << endl;



}

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

int main(){
  int isPrime[1000000];
  for(int i = 2; i < 1000000 ; i++)isPrime[i] = 1;
  isPrime[0]  = isPrime[1] = 0; 
  for(int i = 2 ; i*i < 1000000 ; i++ ){
    if(isPrime[i])for(int j = i*2 ; j < 1000000 ; j+=i)isPrime[j] = 0;
}

  int n;
  while(  cin >> n ){
    int cnt = 0;
    for(int i = 2 ; i <= n ; i++  ){
      if(isPrime[i])cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int flg[1000000];
int main(void)
{
	int n,i,j,c;
	while(scanf("%d",&n)!=EOF){
	c=0;
		for(i=2;i<n;i++){
			flg[i]=0;
		}	
			for(i=2;i*i<=n;i++){
				for(j=2;i*j<=n;j++){
						flg[i*j]=1;	
				}
			}
		for(i=2;i<=n;i++){
			if(flg[i]==0){
					c++;
			}		
		}
	printf("%d\n",c);
	}
	return 0;
}

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

int main() {
	vector<int> primes;
	primes.push_back(2);
	primes.push_back(3);
	for (int n = 4; n != 999; ++n) {
		bool isPrime = true;
		for (int i = 0; i != primes.size(); ++i) {
			if (n % primes[i] == 0) {
				isPrime = false;
			}
		}
		if (isPrime) {
			primes.push_back(n);
		}
	}

	int n;
	while (cin >> n) {
		int count = 0;
		for (int i = 0; i != n; ++i) {
			if (primes[i] <= n)
				++count;
			else 
				break;
		}
		cout << count << endl;
	}

	return 0;
}

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

bool is_prime[1000000];
int number[1000000] = {0};
void init_prime() {
    memset(is_prime, true, 1000000);
    for (int i = 2; i <= 999999; i++) {
        if (is_prime[i]) {
            number[i] = number[i-1]+1;
            for (int j = 2*i; j <= 999999; j+=i)
                is_prime[j] = false;
        } else
            number[i] = number[i-1];
    }
}

int main() {
    init_prime();

    int n;
    while (cin >> n) {
        cout << number[n] << endl;
    }
    return 0;
}

C++: #include <iostream>

int main(){
	int n,d=0;
	
	while(std::cin>>n){
		int N=n;
		for(int a;a<=n;a++){
			for(int b;b<n;b++){
				int c=a/b;
				if(a==c*b){
					d=1;
				}
			}
			if(d==1){
				d=0;
				N--;
			}
		}
		std::cout<<N<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define Max 1000005
bool vis[Max];
int prime[Max],cnt;
void print_prime()
{
    memset (vis,false,sizeof (vis));
    for (long long i=2;i<=sqrt(Max);i++)
        if (!vis[i])
        for (long long j=i*i;j<=Max;j+=i)
        vis[j]=true;
    for (long long i=2;i<=Max;i++)
        if (!vis[i])
        prime[cnt++]=i;
}
int main()
{
    print_prime();
    int n;
    while (scanf("%d",&n)!=EOF) {
        int i=0;
        while (prime[i]<=n) {
            i++;
        }
        printf("%d\n",i);
    }
    return 0;
}

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

bool isChecked[1000010];
vector <int> prime;

int CountPrimeNum(int max) {
	
	int count = 0;
	for (int i = 0; i < 1000000; i++) {
		if (prime[i] > max) break;
		count++;
	}	
	return count;
}


int main() {
	for(int i = 0; i < 1000000; i++) {
		isChecked[i] = false;
	}
	
	isChecked[0] = true;
	isChecked[1] = true;
	
	for (int i = 2; i < 1000000; i++) {
		if(isChecked[i]) continue;
		
		prime.push_back(i);
		
		for (int j = 1;j * i < 1000000;j++) {
			isChecked[i*j] = true;
		}
	}
	
	int n;
	while(cin >> n) {
		cout << CountPrimeNum(n) << endl;
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX_N 999999 + 16
 
int  prime[MAX_N];			
bool is_prime[MAX_N + 1];	
int sieve(const int& n)
{
	int p = 0;
	fill(is_prime, is_prime + n + 1, 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 argc, char *argv[])
{
	int n;
	while (cin >> n)
	{
		cout << sieve(n) << endl;
	}
	return 0;
}