Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt;

    while (scanf("%d", &n) && n!=EOF){
        cnt=0;
        for (int i=2; i<n; i++){
            if (IsPrime(i)) cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}

int IsPrime(int n){
    int i;
    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

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

int a[999999];
int b[999999];

int prime(int x) {
	if (a[x] == 1) return 1;
	else if (a[x] == 2) return 0;
	for (int i = 2; i < sqrt(x) + 1; i++) {
		if (x%i == 0) {
			a[x] = 2;
			return 0;
		}
	}
	return a[x]=1;
}
int main(){
	int n;
	b[0] = 0;
	b[1] = 0;
	b[2] = 1;
	a[0] = 2;
	a[1] = 2;
	a[2] = 1;
	int count = 1;
	for (int i = 3; i <= 999999; i++) {
		if (prime(i))count++;
		b[i] = count;
	}
	while (scanf("%d", &n) != EOF){
		printf("%d\n", b[n]);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int isPrime(int n){
	for(int i=2; i*i<=n; ++i){
		if(n % i == 0){
			return 0;
		}
	}
	return 1;
}

#define MAX_N 1000000

int ans[MAX_N];

main(){
	ans[0] = 0;
	ans[1] = 0;
	for(int i=2; i<MAX_N; i++){
		ans[i] = ans[i-1] + isPrime(i);
	}
	
	int n;
	while(cin>>n){
		cout << ans[n] << endl;
	}
}

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 <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;
}