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 data,i=0,j=2,k=0,l=0,kai[100]={0},s[100000]={0};

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

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

  for(j=0;j<k;j++)
    printf("%d\n",kai[j]);
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main() {
  const long N = 1000000;
  vector<bool> primes(N, true);
  primes[0] = primes[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (!primes[i]) continue;
    for (int j = i * i; j < N; j += i)
      primes[j] = false;
  }
  vector<long> answer(N);
  answer[0] = 0;
  for (long i = 1; i < N; i++)
    answer[i] = answer[i - 1] + primes[i];
  long n;
  while (cin >> n)
    cout << answer[n] << endl;
}

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

#define MAX_NUM (1000000)

int main(void)
{
  static bool searchList[MAX_NUM];
  static bool isPrime[MAX_NUM];
  static int primeNum[MAX_NUM];
  
  double maxSq = sqrt((double)(MAX_NUM - 1));
  
  for (int i = 2; i <= maxSq + 1; i++) {
    if (searchList[i] == false) {
      isPrime[i] = true;
      for (int j = 2; j < MAX_NUM; j++) {
        if (j % i == 0) {
          searchList[j] = true;
        }
      }
    }
  }
  
  for (int i = 2; i < MAX_NUM; i++) {
    primeNum[i] = isPrime[i] ? primeNum[i - 1] + 1 : primeNum[i - 1];
  }
  
  int n;
  while (std::cin >> n) {
    std::cout << primeNum[n] << std::endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 51000000;
const int MOD = 1000000007;

//エラトステネスの篩
int prime[MAX]; //i番目の素数
bool is_prime[MAX]; //素数かどうか

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(){
  ll n;
  while(cin>>n){
    cout<<sieve(n)<<endl;
  }
}

C++: #include <bits/stdc++.h>
#define ll long long
#define mx 1000000+7
bool a[mx+10];
ll pr[mx], p;

using namespace std;
ll sieve(ll n);
int main()
{
    ll i, j,k, l, m, n;
   while(scanf("%lld", &n)==1)
   {
       if(n == 1)
        m = 0;
       else

       m = sieve(n);
    printf("%lld\n", m);
   }

}
ll sieve(ll n)
{
   ll p = 0;
    ll i, j, k;
    k = sqrt(n);
    pr[p++] = 2;
    for(i = 4; i <= n; i+=2)
        a[i]=1;
    for(i = 3; i <= n; i+=2)
    {
        if(a[i] ==0)
            pr[p++]=i;
        if(i <= k)
            if(a[i] == 0)
        {
            for(j = i*i; j <= n; j+=2*i)
                a[j]=1;
        }
    }
    return p;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
const int inf=(1<<31)-1;

int n;
vector<bool> vec;

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

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

using namespace std;

void Eratosthenes(vector<int> &S_List, vector<int> &P_List){
	vector<int>::iterator it = S_List.begin();
	P_List.push_back(*it);  //先頭を素数リストへ追加
	int num = *it;
	while (it != S_List.end()){
		if ((*it % num) == 0){
			it = S_List.erase(it); //探索リストから倍数を除外
		}
		else{
			++it;
		}
	}
	vector<int>::iterator P_it = max_element(P_List.begin(), P_List.end());
	double p_max_sqr = sqrt(*P_it);
	vector<int>::iterator S_it = max_element(S_List.begin(), S_List.end());
	if (S_List.empty() == true){
		return;
	}
	if (*S_it < p_max_sqr){
		return;
	}
	else{
		Eratosthenes(S_List, P_List);
	}
}


void output(vector<int> ex){
	/*vector<int>::iterator it = ex.begin();
	while(it != ex.end()){
		cout << *it << endl;
		++it;
	}*/
	cout << ex.size() << endl;
}

int main(void){
	int num;
	while (cin >> num){
		vector<int> S_List, P_List;
		for (int i=2; i<=num; ++i){
			S_List.push_back(i);
		} 
		Eratosthenes(S_List, P_List);
		output(P_List);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;


using namespace std;

bool isPrime(int n){
	for(int i=3;i<=sqrt((double)n);i++){
		if(n%i==0)return false;
	}
	return true;
}

int main(){
	while(1){
		int n;
		if( !(cin>>n) )break;
		ll sum=1;
		for(int i=3;i<=n;i+=2){
			if(isPrime(i))sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

int main() {
	int n;
	int cnt = 0;
	while(cin >> n) {
		cnt++;
	}
	if(cnt > 1000)
		exit(1);
}

C++: #include<stdio.h>
int isprime(int n){
	int i;
	for(i=2;i*i <= n;i++){
		if(n%i==0)return 0;
	}
	return 1;
}
int main(){
	int sum[100000]={0};
	int i, n;
	sum[0]=0;
	while(scanf("%d",&n) != EOF){
		for(i=2;i<=n;i++){
			if(isprime(i)){
				sum[i+1]=sum[i]+1;
			}else{
				sum[i+1]=sum[i];
			}
		}
		printf("%d\n",sum[n+1]);
	}
	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<<upper_bound(prime.begin(),prime.end(),n)-prime.begin()+1<<endl;
	}
	return 0;
}