Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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

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

int main() {
  Prime();
  int n;
  while(cin >> n) {
    int cnt = 0;
    for (int i = 2; i <= n; i++) if (primes[i]) cnt++;
    cout << cnt << endl;
  }
  return 0;
}

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

int main() {
  int n;
  while (cin >> n) {
    int count = 0;
    if (n >= 2){
      count++;
    }
    for (int i = 3; i <= n; i += 2) {
      for (int j = 2; j < i; j++) {
	if (i % j == 0) {
	  break;
	}
	if (j == i-1) {
	  count++;
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int prime(int x)
{
    int i,j=0,k;
    for(i=2;i<=(x/2);i++)
    {
        if(x%i==0)
        {
            j=1;
            break;
        }
    }
    if(j==1) return 1;
    else return 0;
}
int main()
{
    int i,s,j;
    while(cin>>i)
    {


    s=0;
    for(j=2;j<=i;j++)
    {
        if((prime(j))==0)
        {
            s+=1;
        }

    }
    cout<<s<<endl;
    }



    return 0;
}

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

using namespace std;

long long int num[100000100];

void erat(int n) {
    for (int i = 0; i <= n; i++) num[i] = true;

    num[0] = num[1] = false;

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

int main()
{
    int n, cnt = 0;

    while (cin >> n) {
        erat(n);
        for (int i = 0; i <= n; i++) {
            if (num[i]) cnt++;
        }
        cout << cnt << endl;
        cnt = 0;
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int num, cnt;
	unsigned int i, j, k, data_num;
	int data[50];
	unsigned int sq_num;
	unsigned int *prime;

	for (data_num = 0; data_num < 50; data_num++) {
		data[data_num] = -1;
		scanf("%d", &data[data_num]);
		if (data[data_num] < 0) {
			break;
		}
	}

	for (k = 0; k < data_num; k++) {
		sq_num = (int)sqrt((double)data[k]);
		prime = (unsigned int*)malloc(sizeof(unsigned int) * data[k]);

		for (i = 0; i < data[k]; i++) {
			prime[i] = 1;
		}

		prime[0] = 0;
		for (i = 1; i < sq_num; i++) {
			if (prime[i] == 1) {
				for (j = (i + 1); (i + 1) * j <= data[k]; j++) {
					prime[(i + 1) * j - 1] = 0;
				}
			}
		}

		cnt = 0;
		for (i = 0; i < data[k]; i++) {
			if (prime[i] == 1) {
				cnt++;
				//printf("%d", i + 1);
			}
		}

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

		free(prime);
	}

	return 0;

}

C++: #include <iostream>
#include <cmath>
using namespace std;
#define MAX 1000000


int main(){
	bool work[MAX];
	int num, ans = 0;

	// 入力
	cin >> num;

	// 初期化
	for(int i = 0; i < MAX; i++){
		if(i < 2){
			work[i] = false;
		}else{
			work[i] = true;
		}
	}

	// エラトネスのふるい
	for(int i = 2; i < sqrt((double)MAX) + 1; i++){
		if(work[i] == true){
			for(int j = i * 2; j < MAX; j += i){
				work[j] = false;
			}
		}
	}

	// 計算
	for(int i = 0; i <= num; i++){
		if(work[i] == true){
			ans++;
		}
	}

	// 出力
	cout << ans << endl;

	return 0;
}

C++: #include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int pt[1000000];

int main() {
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 2; i <= n; i++) if (pt[i] == 0) {
        ans++;
        for (int j = i+i; j <= n; j+=i) pt[j] = i;
    }
    printf("%d\n", ans);
    return 0;
}

C++: #include<cstdio>
#include<cstring>
int main(){
 int n,cnt=0;
 scanf("%d",&n);
 int a[n+1];
 memset(a,-1,sizeof(int)*(n+1));
 for(int i=2;i<=n;i++){
 if(a[i]==-1){ cnt++;
 for(int j=i;j<=n;j=j+i) a[j]=0;}
}
printf("%d\n",cnt);
return 0;
}

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

int main()
{
	char prime[999999];
	for (int i = 0; i <= 999999; i++)prime[i] = '1';
	prime[0] = '0';
	prime[1] = '0';
	for (int i = 2; i*i <= 999999; i++)
	{
		if (prime[i] == '1')
		{
			int j = i * 2;
			while (j <= 999999)
			{
				prime[j] = '0';
				j += i;
			}
		}
	}
	int n;
	while (cin >> n)
	{
		int sum = 0;
		for (int i = 0; i <= n; i++)
		{
			if (prime[i] == '1')sum++;
		}
		cout << sum << endl;
	}
	return 0;
}

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

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,soi,max;
	int so[N_MAX],count[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		count[i]=so[i]=0;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	int sq_max = (int)sqrt(max);
	so[0]=so[1]=1;
	for(soi=0,i=2;i<=sq_max;i++){
		if(so[i]>0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=1;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+1-so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

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

void sieve(int n, vector<int> &primes)
{
    vector<bool> v(n + 1, true);

    // check
    for (int i = 2, end = sqrt(n); i <= end; i++) {
        if (!i)
            continue;
        for (int j = i + i; j <= n; j += i)
            v[j] = false;
    }

    for (int i = 2; i <= n; i++)
         if (v[i])
            primes.push_back(i);
}

int main()
{
    vector<int> primes;
    vector<int> inputs;
    int i;

    // read all inputs
    for (int x; cin >> x;)
        inputs.push_back(x);

    // init sieve
    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (auto x : inputs) {
        for (i = 0; i < primes.size(); i++) // find
            if (primes[i] == x) {
                i++;
                break;
            } else if (primes[i] > x)
                break;
        cout << i << endl;
    }

    return 0;
}

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

bool isPrime(int x) {
    if (x==2) {
        return true;
    }
    if (x<2 || x%2==0) {
        return false;
    }
    for (int i=3; i*i<=x; i+=2) {
        if (x%i==0) {
            return false;
        }
    }
    return true;
}
int main() {
    int n;
    int cnt;
    while (cin >> n) {
        cnt=0;
        for (int i=0; i<=n; i++) {
            if (isPrime(i)) {
                cnt++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

C++: #include<iostream>

using namespace std;



bool Prime(int n)
{
	if((n==1)||(n==0))
	{
		return false;
	}
	for(int i=2;i<=n-1;++i)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int n;
	while(cin>>n)
	{
		int count = 0;
		for(int i=0;i<=n;++i)
		{
			if(Prime(i))
			{
				++count;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}