Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

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

using namespace std;

int prime(int n) {
  int i, j, r;
  n++;
  vector<int> primes(n);

  for (i = 2; i < n; ++i)
    primes[i] = i;
  for (i = 2; i*i < n; ++i) {
    if (primes[i])
      for (j = i*i; j < n; j += i)
        primes[j] = 0;
  }
  for (i = r = 0; i < n; i++)
    if (primes[i]) r++;
  return r;
}

int main() {
  int n;
  while(cin >> n)
    cout << prime(n) << endl;
  return 0;
}

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

C++: #include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, j , k , l , n,counter;
 bool ara3[200000];
 void seive()
 {
     for(i= 2; i<=100001; i++)
     {
         ara3[i]  = true;
     }
     ara3[1]  = false;
     for(i=2 ; i<=100001; i++)
     {
         for(j=2;i*j<=100001; j++)
         {
             if(ara3[i]==true)
             {
                 ara3[i*j] = false;
             }
         }
     }
 }
int main(void)
{
    seive();
     while(cin>>n)
     {
         counter = 0;
         for(i=1; i<=n; i++)
         {
             if(ara3[i]==true)
             {
                 counter++;
             }

         }
         cout<<counter<<endl;
     }
     return 0;

}

C++: #include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	int n;
	cin >> n;
	
	vector <bool> p(n+1, true);
	p[0] = p[1] = false;
	for ( int i = 4; i < n; i += 2 )
	{
		p[i] = false;
	}
	for ( int i = 3; i <= n; i += 2 )
	{
		if ( p[i] )
		{
			cout << i << endl;
			for ( int j = i+i; j <= n; j += i )
			{
				p[j] = false;
			}
		}
	}

	int kotae = 1;
	for ( int i = 3; i <= n; i += 2 )
	{
		if ( p[i] )
			kotae++;
	}

	cout << kotae << endl;

	return 0;
}

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


int main() {

	int judge[1000000];
	for(int k=0;k<1000000;k++)judge[k]=1;
	int n;
	
	while(cin>>n){
		int sum = 1;
		for(int i=3;i<n+1;i+=2){
			if (judge[i]==1){
				sum++;
				for(int j=2;j<=n/i;j++)
					judge[i*j] = 0;
			}	
		}
		
		cout << sum <<endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int i,j,c,p;

  while(cin>>n){
    c=1;
    for(i=3;i<=n;i+=2){
      p=0;
      for(j=2;j*j<=i;j+=2){
	if(n%i==0){
	  p=1;
	  break;
	}
      }
      if(p==0){
	c++;
      }
    }
    if(n==1)c=0;
    cout<<c<<endl;
  }
  return 0;
}

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

int main(){
  
  int n;

  while(cin >> n){
    bool Prime[1000000] = {false};
    int i,j;

    for(i = 2; i <= n ; i++){
      if(Prime[i] == false){
        
	for(j = 2; i*j <= n ; j++){
	  Prime[i*j] = true;
	}
      }
    }
    int count = 0;
    for(i = 2 ; i <= n ; i++){
      if(Prime[i] == false){
	count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<cstring>
int prime(long long num)
{
    for(int i=2;i<=sqrt(num);i++)
	if(num%i==0)
	    return 0;
    return 1;
}
int main()
{
    long long n;
    while (scanf("%lld",&n)==1)
    {
    	int sum=0;
    	for (int i=2;i<=n;i++)
    	  if (prime(i)) sum++;
    	printf("%lld\n",sum);
	}
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
const int MAX_N=10000000;
bool data[10000000];
int sum[10000000];
void solve()
{
	for (int i = 2; 2 * i < MAX_N;i++)
	if (data[i])
	for (int j = 2 * i; j < MAX_N; j = j + i)
		data[j] = false;

	data[0] = data[1] = false;

	for (int i = 0; i < MAX_N; i++)
		sum[i + 1] = sum[i] + data[i + 1];
}

int main()
{
	memset(data, true, sizeof(data));
	int n = 0;
	solve();
	while (cin >> n){
		cout << sum[n] << endl;
	}
}

C++: // g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
bool is_prime[1000000];

int main(){
	while(scanf("%d", &n)!=EOF){
		for(int i = 0; i <= n; i++) is_prime[i]=true;
		int res = 0;
		for(int i = 2; i <= n; i++){
			if(is_prime[i]){
				res++;
				for(int j = 2*i; j <= n; j+=i) is_prime[j]=false;
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include<cstdio>
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int x=0;
        for(int j=2;j<=n;j+=2){
            bool a=true;
            for(int i=2;i*i<=j;i+=2){
                if(j==2)break;
                if(j%i==0){
                    a=false;
                    break;
                }
                if(i==2)i--;
            }

            if(a)x++;
            if(j==2)j--;
        }

        printf("%d\n",x);
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
long long const MAX_N = 1000000;
bool prim[MAX_N+1];
long long num_prim(long long n){
	long long count = 0;
	for (int i = 2; i <= n; i++)
		prim[i] = true;
	if (n > 2){
		for (int i = 2; i <= n; i++){
			if (prim[i]){
				for (int j = i * 2;j <= n; j += i){
					prim[j] = false;
				}
			}
		}
		for (int i = 2; i <= n; i++)
			if (prim[i])
				count++;
	}
	else{
		count = n - 1;
	}
	
	return count;
}
int main(){
	long long n;
	while (cin >> n){
		cout << num_prim(n)<<endl;
	}
}

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

int CountPrime(int N);
int CheckPrime(int N);
bool IsPrime(int num);

int main()
{
	int N;

	while (std::cin >> N)
	{
		std::cout << CountPrime(N) << std::endl;
	}
}

int CountPrime(int N)
{
	int Counter = 0;

	for (int i = 1; i <= N; i++)
	{
		Counter = Counter + CheckPrime(i);
	}

	return Counter;
}

int CheckPrime(int N)
{
	if (!IsPrime(N))
		return 0;

	return 1;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????


	double sqrtNum = std::sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

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

using namespace std;

vector<int> Prime;
void PrimeCalc(int n)
{
	bool IsPrime[1000000];
	for(int i = 0; i < 1000000; ++i)
	{
		IsPrime[i] = true;
	}
	IsPrime[0] = IsPrime[1] = false;
	for(int i = 2; i < n; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < n; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	int n;
	cin >> n;
	PrimeCalc(n);
	int ans = 0;
	int pos = 0;
	cout << Prime.size() << endl;
}

int main()
{
	solve();
	return(0);
}