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 <cstdio>
#include <algorithm>
using namespace std;

int n;
bool is_composite[1000001];

int main() {
  while (1) {
    if (scanf("%d", &n) != 1) break;

    fill(is_composite, &is_composite[n+1], false);
    
    int cnt = 0;
    for (int i=2; i<=n; i++) {
      if (!is_composite[i]) {
        cnt++;
        for (int j=i+i; j<=n; j+=i) is_composite[j] = true;
      }
    }

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

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

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	unsigned long long int i;
	int n, p, cnt,fg;
	while (cin >> n) {
		i = 3;
		cnt = 1;
		fg = 0;	
		
		if ((int)log10(n) == 3) {
			cnt = 168;
			i = 1001;
		}
		else if ((int)log10(n) == 4) {
			cnt = 1229;
			i = 10001;
		}
		else if ((int)log10(n) == 5) {
			cnt = 9592;
			i = 100001;
		}

		if (200000 < n) {
			cnt = 17984;
			i = 200001;
		}
		if (300000 < n) {
			cnt = 25997;
			i = 300001;
		}
		if (400000<n) {
			cnt = 33860;
			i = 400001;
		}
		if (500000 < n) {
			cnt = 41538;
			i = 500001;
		}
		if (600000<n) {
			cnt = 49098;
			i =600001;
		}
		if (700000<n) {
			cnt = 56543;
			i = 700001;
		}
		if (800000<n) {
			cnt = 63951;
			i = 800001;
		}
		if (900000<n) {
			cnt = 71274;
			i = 900001;
		}



		for (; i <= n; i+=2) {
			for (int j = 3; j <= (int)sqrt(i); j += 2) {
				if (i%j == 0) {
					fg = 1;
					break;
				}
			}
			if (fg)
				fg = 0;
			else
				cnt++;
		}
		if (n == 1)
			cnt--;
		cout << cnt << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
bool p[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  loop(i,2,M){
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    int res = 0;
    rep(i,n+1)res += p[i];
    cout<<res<<endl;
  }
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

const int size=1000000;
vector<int> map(size,1);
void sieve(int p)
{
    for(int j=p*2;j<size;j+=p)
    {
        map[j]=0;
    }
}
int main(void)
{
    while(1)
    {
        int n;
        int num=scanf("%d",&n);
        if(num != 1)
            break;
        map[0]=0;
        map[1]=0;
        sieve(2);
        sieve(3);
        for(int i=7;i<1000;i+=6)
        {
            sieve(i);
            sieve(i+4);
        }
        printf("%d\n",count(map.begin(),map.begin()+n+1,1));
        return 0;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,ans,flag;
	while(cin>>n,n){
		ans=0;
		for(int i=2;i<=n;i++){
			flag=1;
			for(int j=1;j*j<=i;j++){
				if(i%j==0){
					if(flag==1){
						flag=2;
					}else if(flag==2){
						flag=0;
						break;
					}
				}
			}
			if(flag)
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
int prime[1000000];
int main()
{
    int n, i, j, count;

    for(i=2; i*i<=9999; i++)
    {
        for(j=i*i;j<=999999; j=j+i) prime[j]=1;
    }
    while(scanf("%d", &n)==1)
    {
        count=0;
        for(i=2; i<=n; i++)
        {
            if(prime[i]==0)
            {
                //printf("%d\n", i);
                count++;
            }
        }
        printf("%d\n",count);
    }
    return 0;
}

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

const int limit = 1000000;
std::vector<int> q;

int main(){
    q.push_back(2);
    for(int i = 3; i < limit; i += 2){
        bool f = true;
        for(auto it = q.begin(); it != q.end(); it++){
            int p = *it;
            if(i < p*p) break;
            if(i % p == 0){ f = false; break; }
        }
        if(f) q.push_back(i);
    }
    int n;
    while(std::cin >> n){
        int l = 0, r = q.size()-1, c = -1;
        while(l <= r){
            c = (l + r)/2;
            if(q[c] < n){ l = c + 1; continue; }
            if(q[c] > n){ r = c - 1; continue; }
            break;
        }
        if(l > r) c = r;
        std::cout << c + 1 << std::endl;
    }
}

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

int main(){
  int a,m[1000000],cou=1,j;
  m[1]=0;
  m[2]=1;
  for(int i=3;i<1000000;i++){
    if(i%2==0){
      m[i]=cou;
      continue;
    }
    for(j=3;j*j<=i;j+=2)if(i%j==0)break;
    if(j*j>i)cou++;
    m[i]=cou;
  }
  while(cin>>a){
    cout << m[a]<<endl;
  }
  
 
  return 0;
}

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