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;
#define tablesize 1000010
#include <math.h>

int main(void){
    int table[tablesize];
    for(int i=0;i<tablesize;i++){
        table[i]=1;
    }
    int k;
    table[0]=0;
    table[1]=0;
    for(int i=2;i<(int)sqrt(tablesize)+10;i++){
        if(table[i]==1){
            k=2;
            while(k*i<=tablesize){
                table[k*i]=0;
                k++;
            }
        }
    }

    int n;
    int retval;
    while(cin>>n){
        retval=0;
        for(int i=0;i<=n;i++){
            retval+=table[i];
        }
        cout<<retval<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
 
int prime[999999];
int sum[999999]={0};

void isprime(int n) {
    int i, k;
    for(i = 2; i <= n; i++) {
        prime[i] = 1;
    }
    for(i = 2; i*i <= n; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= n; k += i) {
                prime[k] = 0;
            }
        }
    }
    for(i = 0; i <= n; i++){
        sum[i+1]= sum[i] + prime[i];
    }
}
 
int main() {
    int n, i, count;
    isprime(999999);
    while(scanf("%d", &n) != EOF) {
        count = sum[n+1];
        printf("%d\n", count);
    }
    return 0;
}

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

using namespace std;

void set_prime_number(bool* array, int num) {

  fill(array, array + num, true);
  array[0] = array[1] = false;
  for (int i = 2; i < num; i++) {
    if (!array[i]) continue;
    for (int j = i * 2; j < num; j += i) {
      array[j] = false;
    }
  }

}

int main() {
  bool prime_number[999999];
  int num;
  int nump=0;
  int j=0;
  int cnt=0;

	while(scanf("%d",&num)!=EOF){
	  set_prime_number(prime_number, num);
	 for (int i = 0; i < num; i++) {
	 if (prime_number[i])cnt++;
	 }
	 printf("%d ",cnt);
	 cnt=0;
	}


  while(1){printf("aaaa");}
  return 0;
}

C++: #include<stdio.h>
int main(void){
	int i,j,n;
	bool judge[1000000]={0};
	
	for(i=3; i<1000000; i++)if(i % 2 == 0)judge[i] = 1;
	
	for(i=3; i<500000; i+=2){
		if(judge[i]==0){
			for(j=i*2;j<1000000;j+=i){
				if(j % i == 0){
					judge[j]=1;
				}
			}
		}
	}
	for(;;){
		int count=0;
		scanf("%d",&n);
		if(n==0)break;
		for(i=2;i<=n;i++){
			if(judge[i]==0)count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int MAX = 1000000;
int c[1000010];

int main() {
	int n;
	
	for (int i=0; i<=MAX; i++) c[i] = 1;
	
	for (int j=2; 2*j<=MAX; j++) c[2*j] = 0;
	
	for (int i=3; i<=MAX/2; i++) {
		if (c[i]==0) continue;
		for (int j=2; i*j<=MAX; j++) {
			c[i*j] = 0;
		}
	}
		
	while (cin>>n) {
		
		int ans = 0;
		for (int i=2; i<=n; i++) {
			ans += c[i];
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
  int n,prime[1000000];

  for(int i=0;i<1000000;i++)prime[i]=0;
  prime[0]=prime[1]=1;

  cin >> n;

  for(int i=2;i*i<=n;i++)
    if(prime[i]==0)
      for(int j=2*i;j<=n;j+=i)
	prime[j]=1;
  
  int cnt=0;
  for(int i=0;i<=n;i++)
    if(prime[i]==0)cnt++;

  cout << cnt << endl;

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, Array = int(1e6);

int main(){

  int n, i, j, maxin = 2;
  bool jud;
  vector <int> vec;

  while(cin >> n){
    if(maxin <= n){
      for(i = maxin;i <= n; i++){
        jud = 0;
        for(j = 0;  j < vec.size() ; j++){
          if(vec[ j ] * vec[ j ] > i) break;
          if( !( i % vec[ j ] ) ){
            jud = 1;
            break;
          }
        }
        if(!jud)
          vec.push_back( i );
      }
      maxin = n;
    }
    cout << upper_bound(vec.begin(), vec.end(), n) - vec.begin()   <<endl;
  }
}

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

int main()
{
	int n;
	vector<int> prime;

	while (cin >> n) {
		prime.push_back(2);

		for (int I = 2; I <= n; I++) {
			bool isPrime = true;
			for (int i = 0; i < prime.size(); i++) {
				if (I%prime[i] == 0)
					isPrime = false;
			}
			if (isPrime)
				prime.push_back(I);
		}
		cout << prime.size() << endl;
		prime.clear();
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n,s,ans;
	while(cin >> n){
		ans=0;
		for(int j=2;j<=n;j++){
			s=0;
			for(int i=2;i<=sqrt(j);i++){
				if(j%i==0){
					s++;
				}
			}
			if(s==0){
				ans++;
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

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

C++: #include <stdio.h>
#define MAX 10^6

int main(void)
{
	int n,ans,i,k,j=0;
	int ansbox[MAX];

	for(i=2 ; i<MAX ; i++){
		for(k=2 ; k<=i ; k++){
			if(i%k==0)
				break;
		}
		if(i==k){
			ansbox[j]=k;
			j++;
		}
	}

	while(scanf("%d",&n) != EOF){
		for(i=2 ; i<=n ; i++){
			if(ansbox[i]<=n)
				ans++;
		}
		printf("%d",ans);
		ans=0;
	}
	
	return 0;
}

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

int main(){
	bool is_prime[1000000];

	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}

	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n_prime[1000000];

	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i]=cnt;
	}

	while(true){
		int n;
		cin>>n;

		if(cin.eof())
			break;

		cout<<n_prime[n]<<endl;
	}
	return 0; 
}

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

int main(void){
	int n;
	int i,j;
	int count;
	vector<int> prime(N);

	for(i=0;i<N;i++){
		if(i%2==0||i==1) prime.at(i)=0;
		else prime.at(i)=1;
	}
	prime.at(2)=1;
	for(i=3;i<(N/2);i+=2){
		if(prime.at(i)==1){
			for(j=2;i*j<N;j++){
				prime.at(i*j)=0;
			}
		}
	}
	while(cin >> n){
		count=0;
		for(i=2;i<=n;i++){
			if(prime.at(i)==1) count++;
		}
		cout << count << endl;
	}
	return 0;
}