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 <iostream>

using namespace std;
int main(){
	bool n[1000000];
	for(int i=0; i<1000000; i++){ n[i]=1; }
	n[0]=0;
	n[1]=0;

	for(int i=2; i<1000000; i++){
		if(n[i]==0){ break; }
		if(n[i]==1){
			for(int j=i*2; j<1000000; j+=i){ n[j]=0;	}
		}
	}

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

	return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	unsigned long long int i;
	int n, p, cnt,fg;
	while (cin >> n) {
		i = 3;
		cnt = 0;
		fg = 0;	
		
		if ((int)log10(n) == 3) {
			cnt = 167;
			i = 1001;
		}
		else if ((int)log10(n) == 4) {
			cnt = 1228;
			i = 10001;
		}
		else if ((int)log10(n) == 5) {
			cnt = 9591;
			i = 100001;
		}
		else if ((int)log10(n) == 6) {
			cnt = 78497;
			i = 1000001;
		}


		for (; i <= n; i+=2) {
			for (int j = 3; j <= (int)sqrt(i); j += 2) {
				if (i%j == 0) {
					fg = 1;
					break;
				}
			}
			if (fg)
				fg = 0;
			else
				cnt++;
		}
		if (n >= 2)
			cnt++;
		cout << cnt << 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からでよい(sqrtの部分が < ではwrongAnswer)
			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 <cstdio>
#include <cstring>
#define MAX_N 1000001

bool IsPrime[MAX_N];
int cnt[MAX_N];

// エラトステネスの篩
void get_primes() {
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (int i = 2; i*i <= MAX_N; i++) {
        if (IsPrime[i]) {
            for (int j = i*i; j <= MAX_N; j += i) {
                IsPrime[j]= false;
            }
        }
    }
}

int main() {
    int n;

    memset(IsPrime, 1, sizeof(IsPrime));
    get_primes();

    for (int i = 0; i <= MAX_N; i++) {
        if (IsPrime[i]) { cnt[i]++; }
    }
    for (int i = 1; i <= MAX_N; i++) {
        cnt[i] += cnt[i-1];
    }

    while (scanf("%d", &n) != EOF) {
        printf("%d\n", cnt[n]);
    }

    return 0;
}

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

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

int main() {
	// your code goes here

	int n;
	while(1){
		cin >> n;
		if(cin.eof()){
			break;
		}
		int count = 0;
		for(int i=2;i<=n;i++){
			if(IsPrime(i)){
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[100000]={0};
	for(int i=2;i<100000;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)flag=false;
		}
		if(flag){
		sosu[i]=1;
		}
	}
	while(cin>>n){
	ans=0,cnt=0;
	for(int i=2;i<=n;i++){
		if(sosu[i]==1){
		ans++;
		}
	}
	cout<<ans<<endl;
	}
    return 0;
}

C++: /**************************
½ªg¦éBÁ³È¢æ¤É
**************************/

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

int main()
{
	
	long long int k,p[100000];
	long long int n;
	p[0]=2;
	while(cin>>n){
		if(n<0){
			break;
		}
	k=1;
	int r=(int)sqrt((float)n);
	//mFpfÍÌÜÅKv
	//ÜÅÜí·
	for(int i=3;i<r;i++){
		//»êÜÅÌfÅmF
		for(int j=0;j<k;j++){
			//ÅúÜÅêÈ©Á½çJEgµÄAmFpfÌzñÉi[
			if(i%p[j]==0){
				break;
			}else if(j==(k-1)){
				p[k]=i;
				k++;
			}
		}
	}
	long long int r_k=k;
	for(;r<=n;r++){
		for(long int i=0;i<r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==(r_k-1)){
				k++;
			}
		}
	}
	if(n==1){
		k=0;
		cout<<k<<endl;
	}else if(n==2){
		k=1;
		cout<<k<<endl;
	}else if(n==3){
		k=2;
		cout<<k<<endl;
	}else{
	cout<<k<<endl;
	}
	}
}

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

static const int DATA_NUM = 1000001;
vector<int> prime;
bool isPrime[DATA_NUM];
void primeCalc()
{
	for(int i = 0; i < DATA_NUM; ++i)
	{
		isPrime[i] = true;
	}
	isPrime[0] = isPrime[1] = false;
	for(int i = 0; i < DATA_NUM; ++i)
	{
		if(isPrime[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < DATA_NUM; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	primeCalc();
	int n;
	while(cin >> n)
	{
		int ans = 0;
		for(int i = 0; i <= n; ++i)
		{
			if(isPrime[i])
			{
				++ans;
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<string.h>
using namespace std;
const int N=1000000;
bool isprime[N];
int prime[N];
int k=0;
void init()
{
    isprime[0]=isprime[1]=false;
    for(int i=2;i<N;i++)
    {
        if(isprime[i]) prime[k++]=i;
        for(int j=0;j<k;j++)
        {
            int d=i*prime[j];
            if(d>=N) break;
            isprime[d]=false;
            if(i%prime[j]==0) break;
        }
    }
}
int main()
{
    int n;
    memset(isprime,true,sizeof(isprime));
    init();
    while(cin>>n)
    {
        int i;
        for(i=0;i<k;i++)
            if(n<prime[i])
                break;
        cout<<i<<endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n;
	while(cin>>n)
	{
		int count = 0;
		bool *flag = new bool[n+1]();
		for(int i=2;i<n;++i)
		{
			if (flag[i])
			{
				continue;
			}
			for(int j=i*2;j<n;j+=i)
			{
				flag[j] = true;
			}
		}
		flag[0]=true;flag[1]=true;
		for(int i=0;i<=n;++i)
		{
			if(!flag[i])
			{
				++count;
			}
		}
		cout<<count<<endl;
	}
}

C++: // PrimeNumber.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int n, count,k;

	while(cin >> n){
		count = 1;
		k = 0;

		for(int i = 3; i <= n; i += 2){
			for(int j = 3; j <= sqrt((double)i); j += 2)
			{
				if(i%j == 0){
					k = 1;
					break;
				}
			}
			if(k == 0){
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}