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>

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) REP (i, 0, n)
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

const int MAX_N = 100000000;
bool prime[MAX_N];
void eratos() {
	rep(i, MAX_N) prime[i] = true;
	prime[0] = false;
	prime[1] = false;
	REP(i, 2, sqrt(MAX_N)) {
		if (prime[i]) {
			for (int j = 0; i * (j + 2) < MAX_N; ++j) {
				prime[i * (j + 2)] = false;
			}
		}
	}
}

int main() {
	eratos();
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			if (prime[i]) ans++;
		}
		cout << ans << endl;
	}
}

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

int main()
{
	const size_t MAX = 1000000;

	bitset<MAX> primebox;
	primebox.set();
	primebox.reset(0);
	primebox.reset(1);

	for(int i = 2; i < MAX; i++)
	{
		if(!primebox.test(i))
			continue;

		for(int j = i*2; j < MAX; j += i)
			primebox.reset(j);
	}
		cout << "ok" << endl;

	size_t n;
	while(cin >> n)
	{
		int found;
		if(n < 2)
			found = 0;
		else if(n == 2)
			found = 1;
		else
		{
			found = 1;
			for(size_t i = 3; i <= n; i += 2)
				if(primebox.test(i))
					found++;
		}

		cout << found << endl;
	}

	return 0;
}

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

using namespace std;

int prime(int a){
    int sqt = sqrt(a);
    int array[a+1];
    array[1] = 1;
    array[2] = 0;
    array[3] = 0;
    if(a >= 4){
        for(int i = 2; i <= sqt; i++){
            for(int j = 2; j*i <= a; j++){
                array[i*j] = 1;
            }
        }
    }
    int count = 0;
    for(int i = 1; i <= a; i++){
        if(array[i] == 0) count++;
    }
    return count;
}

int main(){
    int n;
    while(cin >> n){
        cout << prime(n) << endl;
    }
}

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++)
		so[i]=1;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	so[0]=so[1]=0;
	for(soi=0,i=2;i<=1000;i++){
		if(so[i]==0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=0;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

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

int main()
{
	int n, i, j, k=1, wareru=0,cnt;
	long int *sosu = (long int*)malloc(sizeof(long int) * 1000000);
	sosu[0] = 2;
	for (i = 3; i < 1000000; i += 2)
	{
		wareru = 0;
		for (j = 3; j <= sqrt(i*1.0); j += 2)
		{
			if (i%j == 0)
			{
				wareru = 1;
				break;
			}
		}
		if (wareru == 0)
		{
			sosu[k++] = i;
		}
	}

	while (scanf("%d", &n) != EOF)
	{
		if (n == 1)
		{
			printf("0\n");
			continue;
		}
		if (n == 2)
		{
			printf("1\n");
			continue;
		}
		for (i = 0; sosu[i] <= n; i++);
		printf("%d\n", i);
	}
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 999999

//?´???°??????
bool isPrime(int x) {
	if (x < 2)return 0;
	else if (x == 2)return 1;
	if (x % 2 == 0)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}

//??¨????????????????????????
//n??\????????£??´??°????´???°???????????°???????????????is_prime[]???????´?
void eratos(int n, bool is_prime[]) {
	fill(is_prime, is_prime + n, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i*i <= n; i++) {
		if (is_prime[i]) {
			int j = i + i;
			while (j <= n) {
				is_prime[j] = false;
				j = j + i;
			}
		}
	}
}

int main() {
	bool is_prime[MAX];
	eratos(MAX, is_prime);

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

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

using namespace std;

#define MAX_VALUE 1000000

int get_numprime( int num );

int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		int result = get_numprime( num );
		cout << result << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 1; // 2はカウント済み

	bool erat[MAX_VALUE];

	for( int i = 0 ; i < MAX_VALUE ; i++ )
	{
		erat[MAX_VALUE] = true;
	}
	erat[0] = false; erat[1] = false;
	for( int i = 2 ; i <= num ; i++ )
	{
		if( erat[i] )
		{
			for( int j = i*2 ; j <= num ; j+=i )
			{
				erat[j] = false;
			}
		}
	}
	for( int i = 3 ; i <= num ; i+=2 )
	{
		if( erat[i] ) numprime++;
	}

	return numprime;
}

C++: #include <stdio.h>

using namespace std;

int calcLimit(int n){
	int limit;
	for(limit=0;limit*limit<=n;limit++);
	return limit-1;
}

int main(){
	int n,count,limit;

	while(scanf("%d",&n)!=EOF){
		count=0;
		int* array = new int[n+1];
		for(int i=1;i<=n;i++)array[i]=0;
		limit = calcLimit(n);
		for(int i=2;i<=limit;i++){
			if(array[i] == 0)
			{
				for(int j=2*i;j<=n;j+=i){
					if(array[j]==0){
						array[j]=1;
						count++;
					}
				}
			}
		}
		printf("%d\n",n-(count+1));
	}

    return 0;
}

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

int main() {
int b[100000];
for (int k=0;k<100001;k++){
	b[k]=0;
}
for (int p=2;p<100001;p++){
int i,a=0 ;
	i=2;
	while(i<p){
		if(p%i==0){
			break;
	}i=i+1;
	}
	if (i==p){
		a=1;
	}
	b[p]=a;
}
int c[100000];
for (int l=0;l<100001;l++){
	c[l+1]=c[l]+b[l+1];
}
int r;
while(cin>>r){
	cout<<c[r]<<endl;
}
	return 0;
}

C++: #include <stdio.h>
const int MAX_V = 1000000;//1000000?????§????´???°??¨?????????
int prime [999999];//??¨?????????????????????????????????
int sum[1000000];//?´????????????????
int main(){
	
	int i, k, n;
	for(i = 2; i < MAX_V; i++){
		prime[i] = 1;
	}
	for(i = 2; i*i < MAX_V; i++){//??¨?????????????????????????????¨????????????
		if(prime[i] == 1){
			for(k = 2*i; k < MAX_V; k += i){
				prime[k] = 0;//?´???°????????°????´???°??§??????
			}
		}
	}
	for(i = 2; i < MAX_V; i++){//?´????????????????
		sum[i + 1] = sum[i] + prime[i];//
	}
	while(scanf("%d", &n) != EOF){
		printf("%d\n", sum[n + 1]);
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable:4996)

int main()
{
	int DataSet,nCnt,nCnt2,In,Total,Count;

	Total = 0;
	DataSet = 0;

	for (DataSet = 0; DataSet <= 30; DataSet++)
	{
		scanf("%d", &In);
		Total = 1;

		if (In > 2)
		{
			for (nCnt = 3; nCnt <= In; nCnt += 2)
			{
				Count = 0;

				for (nCnt2 = 3; nCnt2 <= sqrt((double)nCnt); nCnt2++)
				{
					if (nCnt%nCnt2 == 0)
					{
						if (nCnt != nCnt2)
						{
							Count++;
							break;
						}
					}
				}
				if (Count == 0)
					Total++;
			}
		}

		printf("%d\n", Total);
	}


	return 0;
}

C++: #include <stdio.h>

int CheckPrime(int n);
int main(void)
{
	static int IsPrime[1000000];
	int i, n, ans;

	for(i=0; i<=999999; i++)
		IsPrime[i]=-1;

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

int CheckPrime(int n)
{
	int i;
	if(n <= 1)return 0;
	if(n == 2)return 1;
	if(n%2==0)return 0;

	for(i=3; i*i<=n; i++)
		if(n%i == 0)return 0;

	return 1;
}