Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <bits/stdc++.h>

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve(){
	fill(prime, prime+MAX, true);
	prime[0] = prime[1] = false;

	for(int i=2; i*i < MAX; i++){
		if(!prime[i]) continue;
		for(int j=i*i; j < MAX; j += i) prime[j] = false;
	}
}


int main(){
	sieve();
	int n;
	while(cin >> n){
		int ret = 0;
		for(int i=0; i<= n; i++){
			if(prime[i]) ret++;
		}
		cout << ret << endl;
	}
}

C++: 
#include <iostream>
#include <cstdio>
using namespace std;
#define OVER_SIX_DIGITS 1000000

int prime[OVER_SIX_DIGITS];

void make_prime(void) {
    for(int r = 0; r < OVER_SIX_DIGITS; r++) prime[r] = 1;
    prime[0] = prime[1] = 0;
    
    for(int r = 2; r < OVER_SIX_DIGITS; r++) {
        if(prime[r]) {
            for(int c = 2 * r; c < OVER_SIX_DIGITS; c += r) prime[c] = 0;
        }
    }
    //累積和配列を作成
    for(int r = 1; r < OVER_SIX_DIGITS; r++) prime[r] += prime[r - 1];
}

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

C++: 
#include <iostream>
using namespace std;
#define MAX_N 999999+16

int prime[MAX_N];
bool is_prime[MAX_N + 1];
int sieve(int n){
	int p = 0;
	fill(is_prime, is_prime + n + 1, 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>
#include <vector>
using namespace std;
const int ub=1e6;

int main(){
	vector<bool> prime(ub, true);
	vector<int> numprime(ub, 0);
	for(int i=2; i<ub; i++){
		if(prime[i]){
			numprime[i] = numprime[i-1]+1;
			for(int j=2; i*j<ub; j++){
				prime[i*j]=false;
			}
		}else{
			numprime[i] = numprime[i-1];
		}
	}
	
	int n;
	while(cin>>n){
		cout << numprime[n] << endl;
	}
	return 0;
}

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

bool IsPrime(int m){
    if(m==1){
        return(0);
    }else if(m==2){
        return(1);
    }else if(m%2==0){
        return(0);
    }else{
        for(int i=3;i*i<=m;i+=2){
            if(m%i==0)return(0);
        }
        return(1);
    }
}

int main(){
    int n;
    int r[30];
    for(int i=0;i<30;i++){
        r[i]=0;
    }
    int j=0;
    while(cin>>n){
        for(int i=1;i<=n;i++){
            if(IsPrime(i))r[j]++;
        }
        cout<<r[j]<<endl;
        j++;
    }
    return(0);
}

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

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

int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		int count=0;
		std::vector<int> num;
		for(int m=2;m<=n;m++){
			bool check=true;
			for(unsigned int i=0;i<num.size();i++){
				if(m!=num[i] && m%num[i]==0){
					check=false;
					break;
				}
			}
			if(check==true){
				if(num.size()>0){
					for(int i=num[num.size()-1];i<m;i++){
						if(i!=m && m%i==0){
							check=false;
							break;
						}
					}
				}
				else{
					for(int i=2;i<m;i++){
						if(i!=m && m%i==0){
							check=false;
							break;
						}
					}
				}
			}
			if(check==true){
				num.push_back(m);
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define N 1000000
vi s(N + 1, 1);
void eli(int p)
{
    for (int i = p + p; i <= N; i = i + p)
    {
        s[i] = 0;
    }
}
void eratos(){
    s[0] = s[1] = 0;
    rep(i, N + 1)
    {
        if (s[i] == 1)
        {
            eli(i);
        }
    }
}
int main(){
    eratos();
    vi sum(N + 1, 0);
    rep(i,N){
        sum[i + 1] = sum[i] + s[i + 1];
    }
    int n;
    while(cin>>n){
        cout << sum[n] << endl;
    }

    return 0;
}

C++: //--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

bool is_prime(int a) {
	int now = 2;
	while (now*now <= a) {
		if (a%now == 0)return 0;
		else now++;
	}
	return 1;
}


int main() {
	while (cin >> n) {
		ll ans = 0;
		bool a[100001];
		for (int i = 2; i <= n; i++) {
			if (a[i] == 1)continue;
			if (is_prime(i))ans++;
			else {
				for (int j = i; j <= n; j += i) {
					a[j] = 1;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int num;
	cin >> num;

	if(num<2){
		cout <<"0"<<endl;
		return 0;
	}

	vector<bool> a(num,true);
	int cnt = num-2;
	for(int ix = 2;ix != num;++ix){
		int jx = 1;
		while((++jx)*ix < num){
			if(a[ix*jx]){
				a[ix*jx] = false;
				cnt--;
			}
		}
	}

	cout <<cnt<<endl;

	return 0;
}

C++: #include<stdio.h>

int main(){
  const int MAX_V = 1000000;
  int prime[MAX_V+1];
  int i, k, v;
  int e, f, ans;
  for(i = 2; i <= MAX_V; i++){
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++){
    if(prime[i]){
      for(k = 2 * i; k <= MAX_V; k += i){
        prime[k] = 0;
      }
    }
  }
  for(e = 0; e < 30; e++){
    int count = 0;
    scanf("%d", &v);
    for(f = 2; f <= v; f++){
      ans = prime[f];
      if(ans == 1){
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

C++: #include <cstdio>

int Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = 0;
	for (int i = 2; i < 1000000; i++){
		Eratos[i] = 1;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = 0;
			}
		}
	}
	int n,res;
	res = 1;
	for (int i = 2; i < 1000000; i++) {
		if (Eratos[i]) {
			Eratos[i] = res;
			res++;
		}
	}
	while (scanf("%d", &n)) {
		res = 0;
		while (!Eratos[n]) {
			n--;
		}
		printf("%d\n",Eratos[n]);
	}
	return 0;
}