Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [100]int
	var inputCount, primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		resultArr[inputCount] = primeCount
		if inputCount == 30 {
			break
		}
		primeCount = 0
		inputCount++
	}
	for _, v := range resultArr {
		fmt.Printf("%d\n", v)
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

C++: #include <iostream>

using namespace std;

const int MAX = 1000000;
bool p[MAX];
int num[MAX];

void prepare() {
    for (int i=0; i<MAX; ++i) p[i] = true;
    p[0] = p[1] = false;
    for (int i=2; i*i<MAX; ++i) {
        if ( ! p[i]) continue;
        for (int j=i*i; j<MAX; j+=i) {
            p[j] = false;
        }
    }
    int sum = 0;
    for (int i=0; i<MAX; ++i) {
        if (p[i]) sum ++;
        num[i] = sum;
    }
}

int main() {
    prepare();
    int n;
    while (cin >> n) {
        cout << num[n] << endl;
    }
    return 0;
}

C++: #include <cstdio>
const int N=1000000;
bool p[N];int pN[N];
main(){p[0]=0;p[1]=0;int i,k,n,c;
for(i=2;i<N;i++)p[i]=1;for(i=2;i*i<N;){for(k=2;i*k<N;k++)p[i*k]=0;do{i++;}while(!p[i]);}for(i=0,c=0;i<N;i++){p[i]&&c++;pN[i]=c;}for(;scanf("%d",&n)+1;printf("%d\n",pN[n]));}

C++: #include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		if ( n <= 0 )
			cout << "0" << endl;
		
		vector <bool> p(n+1, true);

		p[0] = p[1] = false;
		for ( int i = 4; i <= n; i += 2 )
		{
			p[i] = false;
		}

		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
			{
				for ( int j = i+i; j <= n; j += i )
				{
					p[j] = false;
				}
			}
		}

		int kotae = 1;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
				kotae++;
		}

		cout << kotae << endl;
	}

	return 0;
}

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