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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

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

using namespace std;

int setPrimeNumberCount(int n) {
    int count = 0;
    vector<int> primeList;
    vector<int> searchList;
    
    if(n >= 2){
        for(int i = 2; i <= n; i++) {
            searchList.push_back(i);
        }
        
        vector<int>::iterator end_it;
        
        for(int i = 0; i <= n; i++) {
            primeList.push_back(searchList[0]);
            
            for(vector< int >::iterator it = searchList.begin(); it != searchList.end();) {
                if(*it % primeList[count] == 0) {
                    it = searchList.erase(it);
                }
                else {
                    ++it;
                }
            }
            count++;
            if(pow(primeList[i],2) > searchList.back()) {
                for(int i = 0; i < searchList.size(); i++) {
                    primeList.push_back(searchList[i]);
                    count++;
                }
                break;
            }
        }
    }
    return count;
}

int main(void) {
    int n;
    int count = 0;
    
    while(cin >> n) {
        count = setPrimeNumberCount(n);
        cout << count << endl;
        count = 0;
    }
    return 0;
}

C++: #include <Stdio.h>

int main()
{
    int n,i,j,flag=0,cnt,h,k;
    while(scanf("%d",&n) !=EOF)
    {
        if(n==2)
            printf("1");
        else if(n==3)
            printf("2");
        else
        {
            cnt=2;
            h=n/2;
            for(k=4; k<=n; k++)
            {
                for(j=2; j<=h; j+=2)
              {
                if(k%j==0)
                {
                    flag=1;
                    break;
                }
              }
               if(flag==0)
                cnt++;
               else
               flag=0;
            }
            printf("%d",cnt-1);
        }

    }

    return 0;
}

C++: #include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  int i=0;
  int j=0;
  int n=0;
  int a[1000000]={};
  int sum=0;

  while(scanf("%d",&n)!=EOF)
    {
      for(i=0;i<1000000;i++)
        a[i]=1;
      sum=0;

      for(i=2;i<=n;i++)
        {
          if(a[i-1]==0)
            continue;
	  for(j=2;j<=n/i;j++)
            a[i*j-1]=0;
	}

      for(i=1;i<n;i++)
	sum+=a[i];

      cout<<sum<<endl;

    }


  return 0;

}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int sieve(int n);
int prime[1000000];
bool is_prime[1000000];

int main()
{

	int p = 0;
	for (int i = 0; i <= 999999; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999999; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= 999999; j += i) {
				is_prime[j] = false;
			}
		}
	}
	int n;
	while (scanf_s("%d", &n) != EOF) {
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}

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

int main(void)
{
	const  int MAX = 1000000;
	int number =0;
	int count = 0;
	bool noPrim[MAX];
	int p_count=0;

	for(int i=0;i<MAX;i++){
		noPrim[i]=false;
	}
	int j;
	for(int i=2;i<MAX;i++){
		if(noPrim[i]==true)break;
		j=i*2;
		while(j<MAX){
			noPrim[j]=true;
			j+=i;
		}
	}
	while(cin >>  number){
		count = 0;
		for(int i=2;i<=number;i++){
			if(noPrim[i]==false)count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>

#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;
const int MAX = 10000000;
bool isPrime[MAX];
int main(){
  cin.sync_with_stdio(false);
  fill(isPrime,isPrime+MAX,true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < MAX; ++i){
    if(isPrime[i]){
      for(int j = i*2;j < MAX;j+=i){
	isPrime[j] = false;
      }
    }
  }
  int n;
  while(cin >> n){
    int ans = 0;
    for(int i = 2;i <= n;i++){
      if(isPrime[i])ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define MAX_N 1000000

int prime[MAX_N];         // i??????????´???°
bool is_prime[MAX_N + 1]; // is_prime[i]???true????????°i????´???°

// n??\???????´???°?????°?????????
int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = 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(scanf("%d",&n) != EOF){
        cout << sieve(n) << endl;
    }

    return 0;
}

C++: #include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

int MAX_N=1000007;
bool prime[1000007];

int main()
{
	fill(prime,prime+MAX_N,true);

	prime[0]=prime[1]=false;
	for(int i=2;i<MAX_N;i++)
	{
		if(prime[i])
		{
			for(int j=i*2;j<MAX_N;j+=i) prime[j]=false;
		}
	}

	int n;
	while(cin>>n)
	{
		int ans=0;
		rep(i,n+1)
			if(prime[i])
				ans++;
		cout<<ans<<endl;
	}
	


	return 0;
}

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

using namespace std;

#define MAX_NUM	1000000

int solist[MAX_NUM] = { 0 };

int main(int argc, char* argv[])
{
	int i; 
	int num;
	int count;
	int val;

	solist[0] = 1;
	solist[1] = 1;

	for (num = 3; num < MAX_NUM; num += 2) {
		if (solist[num]) continue;
		for (i = num * 2; i < MAX_NUM; i += num) {
			solist[i] = 1;
		}
	}

	while (cin >> val) {
		count = 0;
		for (i = 1; i < val; i += 2) {
			if (solist[i] == 0) count++;
		}
		cout << count << endl;
	}
	
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int const M=31;
int a,hantei[M];

int main(){
  hantei[0]=hantei[1]=1;
  for(int i=2;i<M;i++){
    if(hantei[i]==0){
      for(int j=2;j*i<M;j++){
	if(j*i<M){
	  hantei[j*i]=1;
	}
      }
    }
  }
  for(;cin>>a;){
    int count=0;
    for(int i=0;i<=a;i++){
      if(hantei[i]==0){
	count++;
      }
    }
    cout<<count<<endl;
  }
}