Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <stdio.h>

bool isPrime(int n);

int main(void){
    int n;
    int primes;
    
    while (scanf("%d", &n)!=EOF){
        primes = 0;
        for (int i=2; i<=n; i++){
            if (isPrime(i)) primes++;
        }
        printf("%d\n", primes);
    }
}

bool isPrime(int n){
    if (n==1 || n%2==0) return false;
    if (n==2) return true;
    for (int t=3; t*t<=n; t+=2){
        if (n%t == 0) return false;
    }
    return true;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int data[100000];
	int count;
	c[0]=c[1]=0;
	for(i=2;i<100000;i++){
		c[i]=1;
	}

	while((scanf("%d",&n)!=EOF)&&(n!=0)){
		
		count=0;
		for(i=0;i*i<=n;i++){
			data[i]=count;
			if(c[i]==1){
				for(j=i+1;j<=n;j++){
					if(j%i==0){
						c[j]=0;
					}
				}
			}
		}

		printf("%d",data[n]);
	}
	return 0;
}

C++: #include <stdio.h>

int main() {
    int i, k, v,scan,an;
    int MAX_V = 100000;
    int count[MAX_V];
    int sum[MAX_V];
    int prime[MAX_V];
    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;   
            } 
        }
    }
    count[0]=0;
    for(i=1;i<=MAX_V;i++){
        count[i]= count[i-1]+prime[i];
    }
    while(scanf("%d",&scan)!= EOF){
        an=count[scan]-count[0];
        printf("%d\n",an);
    }
    return 0; 
}

C++: #include <stdio.h>

bool mark[1000000];
void init() {
	for(int i=0; i < 1000000; i++) mark[i] = false;
	
	mark[0] = true;
	mark[1] = true;
	for(int i = 2;i < 1000000;i++)
	{
		if(mark[i])
			continue;
		for(int j = i * 2; j < 1000000; j += i)
		{
			mark[j] = true;
		}
		
	}

}
int main() {
	init();
	int n, count=0;
	
	while(scanf("%d", &n) != EOF) {
		for(int i = 2; i < n;i++)
		{
			if(!mark[i])
			{
				count++;
			}
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}

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

using namespace std;

bool a[1000000];

int main()
{
    memset(a, true, sizeof(a));

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

    int n;
    while (~scanf("%d", &n)) {
        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += a[i];
        printf("%d\n", cnt);
    }
}

C++: #include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
	bool flag[1000000];
	int p;

	for( int i = 0;i <= 999999;i++ ) flag[i] = true;

	for( int i = 0;i <= 999999;i++ ){
		if( flag[i] ) {
			p = i + i + 2;
			for( int k = i + p; k <= 999999;k += p ) flag[k] = false;
		}
	}

	while( cin >> p ){
		int count = 0;
		for( int i = 0;i <= p;i++ ) if( flag[i] ) count++;
		cout << count << endl;
	}
}

C++: #include <iostream>
using namespace std;
// エラトステネスのふるい
int main() {
  int n, prime[1000000];
  while (cin >> n) {
    for (int i = 0; i <= n; i++) {
      prime[i] = 0;
    }
    prime[0] = 1;
    prime[1] = 1;
    
    int count = 0;
    for (int i = 0; i <= n; i++) {
      if (prime[i] == 0) {
	count++;
	for (int j = i; j <= n; j += i) {
	  prime[j] = 1;
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

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

void make_sosu(int ans[]){
    int n, i, j, ind, cnt=0;
    ans[0]=2;ans[1]=3;ans[2]=5;ans[3]=7;
    n=9;
    ind=4;
    while(n<=99999){
        cout << "checing::" << n << endl;
        cnt=0;
        for(i=3;i<n;i++){
            if(n%i==0){
                cnt++;
                break;
            }
        }
        if(cnt==0) {
            ans[ind]=n;
            ind++;
        }   
        n+=2;
     }
}

int main(void){
    int n,i,tmp,ans,sosu[100000]={0};
    make_sosu(sosu);
    while(cin>>n){
        if(n==1) cout << "0" << endl;
        else{
            for(i=0;i<n;i++){
                if(n<sosu[i]){
                    cout << i << endl;
                    break;
                }
            }
        }       
    }
    return 0;
}

C++: #include<iostream>
#define N 1000001
using namespace std;
int main(){
  int n;
  int p[N]={0};
  for(int i=3;i<=N;i+=2) p[i] = 1;
  p[2] = 1;
  for(int i=3;i<=1000;i+=2){
    if(p[i]==1){
      for(int j=2*i;j<=N;j+=i) p[j] = 0;
    }
  }
  while(cin>>n){
    int count = 0;
    if(n==0) break;
    int j = n - 2;
    if(p[j]==1) count++; 
    for(int i=3;i<=n/2;i+=2){
      if(p[i]){
	j = n - i;
	if(p[j]) count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: 



#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

/*
int main(void)
{
	int n;
	vector<int> vecPrime;

	while (cin >> n)
	{
		// vectorの破棄
		vecPrime.clear();

		// nが2以上の時,2のみ追加
		if (n >= 2)
		{
			vecPrime.push_back(2);
		}

		// 奇数のみ探索
		for (int i = 3; i <= n; i += 2)
		{
			// 割り切れたらtrueにする
			bool flagPrime = false;

			// 奇数しかループさせないため、j = 1からでよい
			int size = vecPrime.size();
			for (int j = 1; j < size && vecPrime[j] < sqrt((double)i); j++)
			{
				// 割り切れたら素数でない
				if (i % vecPrime[j] == 0)
				{
					flagPrime = true;
					break;
				}
			}
			// すべて割り切れなかった場合
			if (flagPrime == false)
			{
				vecPrime.push_back(i);
			}
		}

		cout << vecPrime.size() << endl;
	}

	return 0;
}
*/


#define SIZE 100000

int main(void)
{
	int n;
	int prime[SIZE] = {0};

	while (cin >> n)
	{
		int ans = 0;

		// nが2以上の時,2のみ追加
		if (n >= 2)
		{
			prime[0] = 2;
			ans++;
		}

		// 奇数のみ探索
		for (int i = 3; i <= n; i += 2)
		{
			// 割り切れたらtrueにする
			bool flagPrime = false;

			// 奇数しかループさせないため、j = 1からでよい
			for (int j = 1; j < ans && prime[j] < sqrt((double)i); j++)
			{
				// 割り切れたら素数でない
				if (i % prime[j] == 0)
				{
					flagPrime = true;
					break;
				}
			}
			// すべて割り切れなかった場合
			if (flagPrime == false)
			{
				prime[ans] = i;
				ans++;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

int count_prime_number(int n){
	if(n < 2){
		return 0;
	}
	if(n == 2){
		return 1;
	}
	int count = 1;	//2??????
	for(int i = 3; i <= n; i += 2){
		int k = 0;
		for(int j = 3; j <= sqrt(i); j += 2){
			if(i % j == 0){
				k=1;
				break;
			}
		}
		if(k==0){
			count++;
		}
	}
	return count;
}

int main(){
	vector<int> results;
	int in_num;
	while(cin >> in_num){
		results.push_back(count_prime_number(in_num));
	}
	for(auto result : results){
		cout << result << endl;
	}
	return 0;
}

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

bool prime[1000000];//false -> prime
int main(){
    int n = 1000000;

    prime[0] = prime[1] = true;
    for(int i = 2;i*i <= n;i++){

        if(prime[i] == false){
            for(int j = i*i;j <= n;j+=i){
                prime[j] = true;
            }
        }
    }
    while(cin>>n){
        int cnt = 0;
        for(int i = 0;i <= n;i++){
            if(prime[i] == false)cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}