Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

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

#define MAXN 1000005

int a[MAXN];

void judgePrime()
{
    int m=sqrt(MAXN);
    memset(a,0,sizeof(a));
    for(int i=2; i<=m; i++)
    {
        if(!a[i])
        {
            for(int j=i*i; j<MAXN; j+=i)
                a[j]=1;
        }
    }
}

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

C++: #include <stdio.h>
#define MAX 1000000
int isPrime[MAX];
int main(){
int num;
int i, j;
int count;
// 配列の初期化
isPrime[0] = isPrime[1] = 0;
for(i = 2; i < MAX; i++){
isPrime[i] = 1;
}
// エラストテネスのふるい
for(i = 2; i * i < MAX; i++){
if(isPrime[i]){
// iの倍数は素数じゃないのでフラグ変更
for(j = 2 * i; j < MAX; j+=i){
isPrime[j] = 0;
}
}
}
while(scanf("%d", &num) != EOF){
count = 0;
while(num){
count += isPrime[num--];
}
printf("%d\n", count);
}
return 0;
}

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

int main() {
	int n,i,j,a=0,b=0;
	while (cin >> n) {
		if(n>=9) {
			for (i = 9; i <= n; i++) {
				a=0;
				for (j = 3; j <= n; j++) {
					if (i%j == 0) {
						a++;
						break;
					}
					j++;
					b += a;
				}
				i++;
			}
		}
		if (n == 2)cout << "1" << endl;
		else if (n == 3)cout << "2" << endl;
		else if (n == 5) cout << "3" << endl;
		else if (n == 7)cout << "4" << endl;
		else if (n % 2 == 0) cout << n / 2 - b - 1 << endl;
		else cout << (n + 1) / 2 - b - 1 << endl;
	}
	return 0;
}

C++: #include <stdio.h>

const int MAX_V = 1000000;

int p[MAX_V+1];
int data[MAX_V];
int main() {
    int i,k,a;
    for(i = 2;i<=MAX_V;i++) {
        p[i] = 1;
    }
    for(i = 2;i*i<=MAX_V;i++) {
        if(p[i]) {
            for(k = 2*i;k<=MAX_V;k+=i) {
                p[k] = 0;
            }
        }
    }
    for(i = 0;i<=MAX_V;i++){
        data[i+1] = data[i]+p[i];
    }
    while(scanf("%d",&a) != EOF){
        printf("%d\n", data[a + 1]);
    }
    return  0;
}

C++: #include<iostream>
#include<cstring>
#include<math.h>
using namespace std;
const int MAX = 1000000;
int prime(int n)
{
	int ans = 0;
	bool prime[MAX];
	memset(prime, 0, sizeof(prime));
	for (int i = 2; i < n;i++)  
	{ 
		for (int j = 2; j <= n / i; j++)
		{
			if (i*j <= n)
				prime[i*j] = 1;
		}
	}
	for (int i = 2; i <= n; i++)
	{
		if (!prime[i])
			ans++;
	}
	return ans;
}
int main()
{
	int n, m = 0;
	while (cin >> n&&m<30)
	{
		cout << prime(n) << endl;
		m++;
	}
	return 0;
}

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

int arr[1000000];

void ar()
{
	int cnt;
	arr[2] = 1;
	int j;
	int i = 3;
	for (; i < 100000; ++i) {
		cnt = 1;
		for (j = 2; j < i; ++j) {
			if (i%j == 0) {
				arr[i] = arr[i - 1];
				--cnt;
				break;
			}
		}
		arr[i] = arr[i - 1] + cnt;
	}
}

int main()
{
	int x;
	ar();
	while (cin >> x) {
		cout << arr[x] << endl;
	}
	return 0;
}

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

C++: #include <iostream>
#include <math.h>

int prime[1000000];


bool isPrime(int n) {
  int x = (int)sqrt(n);
  for (int i = 3; i <= x; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
 
  return 0;
}

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

using namespace std;

// エラトステネスの篩 : [0, n] の素数表を返す
// 計算時間 O(n log log n), 領域 O(n)
vector<bool> SieveOfEratosthenes(const int n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;

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

    return is_prime;
}

// i \in [0, n] 以下の素数の数を求める
// 計算時間 O(n log log n), 領域 O(n)
vector<int> CountPrime(const int n) {
    vector<bool> is_prime = SieveOfEratosthenes(n);
    vector<int> count(n + 1);

    for (int i = 2; i <= n; ++i)
        count[i] += count[i - 1] + is_prime[i];

    return count;
}


int main() {
    cin.tie(0); ios::sync_with_stdio(false);

    auto cnt_prime = CountPrime(999999);
    int n;
    while (cin >> n)
        cout << cnt_prime[n] << '\n';

    return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
    int a,f,counter;
    while(cin>>a)
    {
        counter=1;
        for(int i=3;i<=a;i++)
        {
            f=0;
            for(int j=2;j<i;j++)
            {
                if(i%j==0)
                {
                    f=1;
                    break;
                }
            }
            if(f==0)
                counter++;
        }
        cout<<counter<<endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	int ans[100000];
	int count = 0;
	int ans_count = 0;
	while (cin >> n) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (i%j == 0 && j != 1 && j != i)
				{
					count++;
				}
			}
			if (count == 0) {
				ans_count++;
			}

			count = 0;

		}
		cout << ans_count - 1 << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n, cnt;		
	while(cin >> n){
		//??????????????????1???????????\??±??????
		bool prime[n+1] = {false};
		prime[1] = true;
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(!prime[j]){
				for(int k = j; k*j <= n; k++){
					prime[j*k] = true;
				}
			}
		}
		cnt = 0;
		//false?????¨????´???°
		for(int i = 1; i <= n; i++){
			if(!prime[i]) cnt++;
		}
		cout << cnt << endl;
	}
}

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

using namespace std;

int main() {
  const int N_MAX = 1000000;
  int table[N_MAX];

  for (int i = 0; i < N_MAX; i++) {
    table[i] = 0;
  }
  table[0] = table[1] = 1;
  int sq = sqrt(N_MAX);
  for (int i = 2; i < sq+1; i++) {
    if (table[i] == 0) {
      for (int j = i*2; j < N_MAX; j += i) {
        table[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n) {

    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (table[i] == 0) ans++;
    }
    cout << ans << endl;

  }

  return 0;
}

C++: 

#include<iostream>
#include<math.h>
main(){
	int i,j,n,p[1000000];
	std::cin>>n;
	for(i=2;i<=n;i++)
		p[i]=1;
	for(i=2;i<n;i++)
		for(j=2;i*j<=n;j++)
			p[i*j]=0;
	j=0;
	for(i=2;i<=n;i++)
		j+=p[i];
	std::cout<<j<<std::endl;
}

C++: int main(){
	int i , j , n , pn , cn=0;
	
	while(cin>>n){
		pn=1;
		for(i=3 ; i<=n ; i++){
			for (j=2 ; j<i ; j++){
				if (i%j==0) goto skip;
			}
			pn++;
			skip:;
		}
		if(n==0 || n==1 ) {
			cout << 0 << endl;
		} else {
			cout << pn << endl;
		}
		cn++;
		if(cn>=30) break;
	}
	return 0;
}