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>

using namespace std;
int main(){
	static bool cmp[1000000] = {true};
	static int ans[1000000];
	for(int i=2; i<1000000;i++){
		if(!cmp[i]){
			for(int j=2;j*i<1000000;j++){
				cmp[i*j] = true;
			}
		}
		ans[i] = ans[i-1]+!cmp[i];
	}
	for(int n; cin>>n; n++){
		cout<<ans[n]<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
 
#define MAX 1000000
 
int main(){
    char prime[MAX];
    int num, i, j, ans;
 
    for(i = 0; i < MAX; i++)
    {
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for(i = 2; i < (MAX/2); i++)
    {
        if(prime[i])
        {
            for(j = 2*i; j < MAX; j += i)
            {
                prime[j] = 0;
            }
        }
    }
     
    while(scanf("%d", &num) != EOF)
    {
        ans = 0;
         
        for(i = 3; i <= num; i+=2)
        {
            ans += prime[i];
        }
         
        printf("%d\n", ans);
    }
 
    return 0;
}

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

int main()
{
	long int n,m;
	while(cin>>n){
		long int i;
		int number[10000]={0};
		int ans=0;

		for(i=0;i<n;i++){
			if(number[i]==0){
				ans++;
				for(m=i;m<n;m+=i){
					number[i]=1;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
	vector<int> p;
	int n;
	p.push_back(2);
	for(int i=3;i<999999;i++){
		for(int j=0;;j++){
			if(i%p[j]==0)
			break;
			if(i<p[j]*p[j]){
			p.push_back(i);
			break;
			}
		}
	}
	while(cin >> n){
		int i=0;
		while(n>=p[i]){
			i++;
		}
		cout << i << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool P[1000000];

int main() {
    int n, ans;
    while (cin >> n) {
        fill(P, P + n + 1, true);
        P[0] = P[1] = false;
        for (int i = 0; i * i <= n; i++) {
            if (P[i]) {
                for (int j = i + i; j <= n; j += i) {
                    P[j] = false;
                }
            }
        }
        ans = 0;
        for (int i = 0; i <= n; i++) if (P[i]) ans++;
        cout << ans << endl;
    }
}

C++: #include<stdio.h>
#include<math.h>
#include<cmath>
#include<vector>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1e-8
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) (a<b?a:b)
#define ll long long
#define INF 9223372036854775807
int prime[1000005];
bool isprime[10000005];
int num;
int main()
{
    for(int i=2;i<1000005;i++)
    {
        if(isprime[i])
            continue;
        prime[num++]=i;
        for(int j=2*i;j<1000005;j+=i)
        {
            isprime[j]=1;
        }
//        if(i<100)
//            printf("%d\n",prime[num-1]);
    }
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int ans=upper_bound(prime,prime+num,n)-prime;
        printf("%d\n",ans);
    }
    return 0;
}

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

int main()
{
    std::vector<bool> is_prime(3);
    is_prime.at(0) = is_prime.at(1) = false;
    is_prime.at(2) = true;

    int n, n_max = 1;
    int cnt;
    while (std::cin >> n) {
        if (n_max < n) {
            is_prime.resize(n + 1, true);

            for (auto i = 2; i <= n / 2; i++) {
                if (is_prime.at(i) == true) {
                    for (auto j = 2 * i; j <= n; j += i) {
                        is_prime.at(j) = false;
                    }
                }
            }

            n_max = n;
        }

        cnt = 0;
        for (auto i = 2; i <= n; i++) {
            if (is_prime.at(i) == true) {
                cnt++;
            }
        }

        std::cout << cnt << std::endl;
    }

    return 0;
}

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

int main(){
int n;
while(cin>>n){
	if(n==0)break;
	int m=0;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
    int n, ans, cnt, prime;

    while(cin >> n){
      prime = 1;
      if(n == 1) cout << 0 << endl;
      if(n == 2) cout << 1 << endl;
      if(n == 3) cout << 2 << endl;

      if(n >= 4){
      for(int i=3; i <= n; i++){
        cnt = 0;
        for(int j=3; j <= sqrt(i); j += 2){
          if(i%j == 0) cnt++;
        }
        if(cnt == 0  && i%2 != 0) prime++;
      }
      cout << prime << endl;
    }
    }
    return 0;
}

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

int pn[1000002];

int main(){
int n, Count;
cin.tie(0);
while(scanf("%d",&n)!=EOF){
Count=0;
memset(pn,0,n);
pn[0]=pn[1]=1;
for(int i=2;i<=n;i++) if(!pn[i]) for(int j=1;i*j<=n;j++) pn[i*j]=1;
for(int i=2;i<=n;i++) if(!pn[i]) Count++;
cout<<Count<<endl;
}
return 0;
}