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 <list>
#include <algorithm>

using namespace std;

int main() {
  int n;
  
  while(!cin.eof()) {
    cin >> n;
    list<int> search_list(n-1);
    list<int> prime_number;
    while(n!=1) {
      search_list.push_front(n);
      n--;
    }
    while(!search_list.empty()) {
      int m = search_list.front();
      prime_number.push_back(m);
      search_list.pop_front();
      list<int>::iterator it = search_list.begin();
      while(it!=search_list.end()) {
	if((*it % m) == 0){
	  it = search_list.erase(it);
	  continue;
	}
	it++;
      }				   
    }
    cout << prime_number.size() << endl;
    prime_number.clear();
    search_list.clear();
  }
}

C++: #include<iostream>
using namespace std;
int main(){
	bool num[1000000] = {0};
	for(int i=2; i<1000000; i++){
		if(!num[i]){
			for(int j=i*2; j<500000; j+=i){num[j] = true;}
		}
	}
	int n;
	while(cin >>n){
		int f = 0;
		for(int i=2; i<=n; i++){
			if(!num[i]){f++;}
		}
		cout <<f<<endl;
	}
}

C++: #include <iostream>

using namespace std;
int main(){
	bool n[1000000];
	for(int i=0; i<1000000; i++){ n[i]=1; }
	n[0]=0;
	n[1]=0;

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

	int num;
	int count;
	while(cin >> num){
		count = 0;
		for(int i=2; i<=num; i++){
			count += n[i];
		}
		cout << count << endl;
	}

	return 0;
}

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

bool Prime(int n);

int main(){

  int n;
  int sum;

  while(cin >> n){
    sum = 0;
    for(int i=3; i<=n; i+=2){
      sum += Prime(i);
    } 
    cout << sum+1 << endl;
  }

  return 0;
}


bool Prime(int n){

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

  else{
    for(int i=3; i<=sqrt(n); i+=2){
      if(n%i == 0)
	return false;
    }
  }

  return true;
}

C++: #include <bits/stdc++.h>
using namespace std;

long long i,j,sum[1000005],total,n;
bool a[1000005];


int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	for(i=2; i<1000000; i++){
//		cout<<i<<'\n';
		if(a[i]==false){
			j=i*i;
			while(j<1000000){
				a[j]=true;
				j+=i;
			}
		}
	}
	
	a[1]=true;
	total=0;
	for(i=1; i<1000000; i++){
		if(a[i]==false){
			total++;
		}
		sum[i]=total;
	}
	while(cin>>n){
		cout<<sum[n]<<'\n';
	}
	
return 0;
}

C++: 
 int main()
 {
     int num, i, j;
     cout<<"Enter an Integer:"<<endl;
                  cin>>num;
                  
                  for(i=0; i<=num; i++)
                  {
                           for(j=2; j<=i; j++)
                           {
                                    if(i%j == 0)
                                    {
                                    break;
                                    }
                                    else if (i == j+1)
                                    {
                                     cout<<i<<endl;    
                                         }
                                    }
                           }
    
}

C++: #include <iostream>
using namespace std;
int main()
{
	int A[30] = {};
	int P[1000000] = {};
	int c = 0, j;
	for (int k = 2; k < 1000000; ++k){
		if (P[k] == 0){
			P[k] = ++c;
			for (j = 2; j * k < 1000000; ++j)
				P[j * k] = -1;
		}
		else if (P[k] == -1)
			P[k] = c;		
	}
	int k;
	while (cin >> k)
		cout << P[k] << "\n";
	return 0;
}

C++: #include <iostream>
using namespace std;
#define tablesize 1000010
#include <math.h>

int main(void){
    int table[tablesize];
    for(int i=0;i<tablesize;i++){
        table[i]=1;
    }
    int k;
    table[0]=0;
    table[1]=0;
    for(int i=2;i<(int)sqrt(tablesize)+10;i++){
        if(table[i]==1){
            k=2;
            while(k*i<=tablesize){
                table[k*i]=0;
                k++;
            }
        }
    }

    int n;
    int retval;
    while(cin>>n){
        retval=0;
        for(int i=0;i<=n;i++){
            retval+=table[i];
        }
        cout<<retval<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
 
int prime[999999];
int sum[999999]={0};

void isprime(int n) {
    int i, k;
    for(i = 2; i <= n; i++) {
        prime[i] = 1;
    }
    for(i = 2; i*i <= n; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= n; k += i) {
                prime[k] = 0;
            }
        }
    }
    for(i = 0; i <= n; i++){
        sum[i+1]= sum[i] + prime[i];
    }
}
 
int main() {
    int n, i, count;
    isprime(999999);
    while(scanf("%d", &n) != EOF) {
        count = sum[n+1];
        printf("%d\n", count);
    }
    return 0;
}

C++: #include <stdio.h>
#include <algorithm>

using namespace std;

void set_prime_number(bool* array, int num) {

  fill(array, array + num, true);
  array[0] = array[1] = false;
  for (int i = 2; i < num; i++) {
    if (!array[i]) continue;
    for (int j = i * 2; j < num; j += i) {
      array[j] = false;
    }
  }

}

int main() {
  bool prime_number[999999];
  int num;
  int nump=0;
  int j=0;
  int cnt=0;

	while(scanf("%d",&num)!=EOF){
	  set_prime_number(prime_number, num);
	 for (int i = 0; i < num; i++) {
	 if (prime_number[i])cnt++;
	 }
	 printf("%d ",cnt);
	 cnt=0;
	}


  while(1){printf("aaaa");}
  return 0;
}

C++: #include<stdio.h>
int main(void){
	int i,j,n;
	bool judge[1000000]={0};
	
	for(i=3; i<1000000; i++)if(i % 2 == 0)judge[i] = 1;
	
	for(i=3; i<500000; i+=2){
		if(judge[i]==0){
			for(j=i*2;j<1000000;j+=i){
				if(j % i == 0){
					judge[j]=1;
				}
			}
		}
	}
	for(;;){
		int count=0;
		scanf("%d",&n);
		if(n==0)break;
		for(i=2;i<=n;i++){
			if(judge[i]==0)count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int MAX = 1000000;
int c[1000010];

int main() {
	int n;
	
	for (int i=0; i<=MAX; i++) c[i] = 1;
	
	for (int j=2; 2*j<=MAX; j++) c[2*j] = 0;
	
	for (int i=3; i<=MAX/2; i++) {
		if (c[i]==0) continue;
		for (int j=2; i*j<=MAX; j++) {
			c[i*j] = 0;
		}
	}
		
	while (cin>>n) {
		
		int ans = 0;
		for (int i=2; i<=n; i++) {
			ans += c[i];
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
  int n,prime[1000000];

  for(int i=0;i<1000000;i++)prime[i]=0;
  prime[0]=prime[1]=1;

  cin >> n;

  for(int i=2;i*i<=n;i++)
    if(prime[i]==0)
      for(int j=2*i;j<=n;j+=i)
	prime[j]=1;
  
  int cnt=0;
  for(int i=0;i<=n;i++)
    if(prime[i]==0)cnt++;

  cout << cnt << endl;

  return 0;
}