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 <stdio.h>

int main(void)
{
	int n;
	
	while(scanf("%d", &n) != EOF){
	
	bool *d = new bool [n+1];
	int count = 0;

	for(int i = 0; i <= n; i++)
		d[i] = true;

	for(int i = 2; i <= n; i++){
		if(d[i]){
			count++;
			for(int j = i*2; j <= n; j+=i)
				d[j] = false;
		}
	}
	printf("%d\n", count);
	}


	return 0;
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> prime;
void init(){
	for(int i=2;i<999999;i++){
		bool isprime=true;
		for(vector<int>::iterator p(prime.begin());p!=prime.end();p++){
			if((*p)*(*p)>i)break;
			if(i%*p==0){
				isprime=false;
				break;
			}
		}
		if(isprime){
			prime.push_back(i);
		}
	}
}
int main(){
	int n;
	init();
	while(cin>>n){
		cout<<lower_bound(prime.begin(),prime.end(),n)-prime.begin()+1<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n[99999],j,o=0;
	for(int i=2;i<=99999;i++){
		n[i]=1;
		
	}
	n[0]=n[1]=0;
		for( j=2;j<=99999;j++){
			if(n[j]){
				for(int k=j*2;k<=9999;k+=j){
				n[k]=0;
				}
			}
		}
		while(cin>>a){
	for(int k=2;k<=a;k++) if(n[k]) o++;
	cout<<o<<endl;
		}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>

#define PI 3.14159265359

#define INF 1000000;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

typedef long long ll;

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/

int prime[1000000];
bool is_prime[1000001];

int sieve(int n)
{
	int p = 0;
	
	for (int i=0; i<=n; i++) is_prime[i] = 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 n;
	
	while (cin >> n)
	{
		cout << sieve(n) << endl;
	}
	
	return 0;
}

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

#define REP(i, N) for(int i = 0; i < N; i++) 

const int N = 1000 * 1000;
int isPrime[1000 * 1000];

int main() {
  REP(i, N) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 0; i < N; i++)
    if( isPrime[i] ) {
      for(int j = i + i; j < N; j += i)
        isPrime[j] = false;
    }

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

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


int main(void){

	
	int n,count;
	

	while (cin >> n){
		vector <int> list(n+1, 0);

		for (int i = 2; i < n+1; i++){
			list[i] = i;
		}//???????????????????????°???????????????

		//??????????????§?¨???????????????????????????\??£???????????????????´???°?¢????
		for (int i = 2; i < sqrt(n)+1; i++){
			//??????????????\??£??????????´???°???????????????????????????
			if (list[i] == i){//0???????????¢?????§?????°???????????°????????§??????
				//?????????????????????????????§????????°????´???°??§??????
				//????????°????????°???0?????£??\??????
				for (int j = i * 2; j < n+1; j += i){
					list[j] = 0;
				}					
			}
			
				
			}

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

		}cout << count << endl;
		
		
		}//while?????????



	return 0;
}

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

using namespace std;

bool isPrime(int x)
{
	bool is_prime = true;
	if (x == 1) is_prime = false;
	for (int i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
		{
			is_prime = false;
			break;
		}
	}
	return is_prime;
}

int countPrime(int x)
{
	int count = 0;
	for (int i = 2; i <= x; i++)
	{
		if (isPrime(i))
		{
			count++;
		}
	}
	return count;
}

int main()
{
	int n;
	while (cin >> n, !cin.eof())
	{
		cout << countPrime(n) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000003]={0};
	
	for(int i=2;i<1000002;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0){
			flag=false;
			break;//素数でない時点で打ち切り
			}
		}
		/*if(flag){
		cnt++;
		sosu[i]=cnt;
		}*/
		sosu[i]=(flag)? cnt++ : cnt;		
	}
	//for(int i=0;i<30;i++)cout<<sosu[i]<<" ";
	while(cin>>n){
	cout<<sosu[n]<<endl;
	}
    return 0;
}

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

using namespace std;


int main() {
	int n;
	bool p[1000000];

	p[0] = 0;
	p[1] = 0;

	for(int i = 2; i <= 999999; i++) {
		p[i] = true;
	}

	for(int i = 2; i * i <= 999999; i++) {
		for(int j = 2; j * i <= 999999; j++) {
			p[j * i] = false;
		}
	}

	while(cin >> n) {
		int count = 0;
		for(int i = 2; i <= n; i++) {
			if(p[i] == true) {
				count++;
			}
		}

		cout << count << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <cmath>
std::vector<int> PRIMES;

void init_primes(int max)
{
  if (max < 2) return;
  std::set<int> candidate;
  PRIMES.push_back(2);
  for (int i = 3; i < max; i+=2) {
    candidate.insert(i);
  }
  for (int i = 3; i < sqrt(max); i+=2) {
    std::set<int>::iterator it = candidate.find(i);
    if (it != candidate.end()) {
      PRIMES.push_back(i);
      int del_num = i;
      while (del_num < max) {
        it = candidate.find(del_num);
        if (it != candidate.end()) candidate.erase(it);
        del_num += i;
      }
    }
  }
  for (std::set<int>::iterator it = candidate.begin();
       it != candidate.end(); ++it) {
    PRIMES.push_back(*it);
  }
}

int main()
{
  const int max = 1000000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i && it != PRIMES.end()) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
/*
bool isPrime(int n) {
  for(int i = 2; i < n; ++i) {
	if(n % i == 0) return false;
  }
  return true;
}
*/

bool isPrime(int x) {
  if (x == 2) return true;

  else if (x < 2 || x % 2 == 0) return false;

  int i = 3;
  while(i <= sqrt(x)) {
	if(x % i == 0) return false;
	i += 2;
  }
  return true;
}

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