Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

C++: #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=10000000+5;
int prime[maxn];
bool p[maxn];
int cnt=0;
void is_prime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=maxn;i++)
        if(p[i]) {
            prime[cnt++]=i;
            for(int j=i*i;j<=maxn;j+=i)
                 p[j]=false;
        }
}
int main()
{
    is_prime();
    int n;
    while(scanf("%d",&n)==1)
    {
        int k=lower_bound(prime,prime+cnt,n)-prime;
        if(prime[k]==n) k++;
        printf("%d\n",k);
    }
    return 0;
}

C++: /*#include <cstdio>
#define MAX 1000

int main(){
	int n;
	bool c[MAX]={true};
	int t[MAX];t[0] = 0;
	for(int i = 2;i < MAX;i++){
		for(int j = i;i*j < MAX;j++){
			c[i*j-1] = true;
		}
	}
	for(int i = 1;i < MAX;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	return 0;
}*/

#include <cstdio>

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j-1] = true;
		}
	}
	for(int i = 1;i < 1000000;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	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(void) {
	int n;
 while(cin >> n){	
    int count = 1;
    
    for(int i=3;i<=n;i=i+2){
        if(IsPrime(i)) count++;
    }
    cout << count << endl;
    count = 0;
}

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

int count_prime( unsigned int const& n )
{
    if ( n <= 0 || 1000000 <= n ) return -1;
    std::vector<bool> memo_prime( n+1, true );
    for ( unsigned int i = 2; i < n; ++i )
    {
        for ( unsigned int j = 2; i*j <= n; ++j )
        {
            memo_prime.at(i*j) = false;
        }
    }
    memo_prime.at(0) = memo_prime.at(1) = false;
    memo_prime.at(2) = true;
    return std::count( memo_prime.begin(), memo_prime.end(), true );
}

int main()
{
    int n;
    while( std::cin >> n)
        std::cout << count_prime(n) << std::endl;
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 100000

int main() {
	int p[N] = {}, i, j,n,cnt;
	for (i = 2; i <= sqrt(N); i++) if (!p[i]) for (j = i*i; j < N; j += i)p[j] = 1;
	while (cin >> n) {
		cnt = 0;
		for (i = 2; i <= n; i++) if (!p[i]) cnt++;
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
//#include <math.h>
//#include <string>
#include <cmath>
#include <iomanip>

int main();
int count_prime_number(int n);

int main(){
	int input;
	std::vector<int> answer;
	
	
	//for (int i = 0; i < 3; i++){
		//std::cin >> input;
	while (std::cin >> input){
		answer.push_back(count_prime_number(input));
	}

	for (int i = 0; i < answer.size(); i++){
		std::cout << answer[i] << std::endl;
	}

	//while (1);
	return 0;
}

/**
* nまでの素数の個数を出力する
* args:数値n
* return:素数の個数
* 参考:http://tsg.ne.jp/TT/tsg/c/mansaku/P01.html
*/
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i += 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j += 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

C++: //#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
#include <time.h>

using namespace std;

#define N_MAX 1000000

int kouho[N_MAX / 2];

int main(){

	clock_t c1,c2;
	c1 = clock();

	vector <int> sosuu;
	int check;
	//int kouho[N_MAX / 2];
	int n;
	int cnt;


	for (int i = 0; i < N_MAX / 2; i++){
		kouho[i] = i * 2 + 1;
	}
	kouho[0] = 0;

	sosuu.push_back(2);
	check = 3;

	while (check < 1000){
		sosuu.push_back(check);
		for (int i = check; i < N_MAX; i += (check*2)){
			kouho[(i - 1) / 2] = 0;
		}

		for (int i = check/2; i < N_MAX / 2; i++){
			if (kouho[i] != 0){
				check = kouho[i];
				break;
			}
		}
	}


	
	while (cin >> n){
		cnt = 0;
		if (n <= 1000){
			for (int i = 0; i < sosuu.size(); i++){
				if (sosuu[i] <= n)cnt++;
				else break;
			}
		}
		else{
			cnt += sosuu.size();
			for (int i = 0; i < N_MAX /2; i++){
				if (kouho[i] > n){
					break;
				}
				else{
					if (kouho[i] != 0)cnt++;
				}
			}
		}
		cout << cnt << endl;
	}

	c2 = clock();

	cout << "time = " << (double)(c2 - c1) / CLOCKS_PER_SEC << "[sec]" << endl;


	return 0;
}

C++: #include <iostream>
int main(){
    int i,j,ch[1000000];

    for(i=0;i<1000000;i+=2){ch[i]=0;ch[i+1]=1;}

    ch[1]=0;
    ch[2]=1;

    for(i=3;i<1000;i+=2) if(ch[i]) for(j=i<<1;j<1000000;j+=i) ch[j]=0;

    for(i=3;i<1000000;i++) ch[i]+=ch[i-1];

    while(cin>>i) cout<<ch[i]<<endl;

    return 0;
}

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

int main(void){
    int num;
    while(cin>>num){
        int ans=0;
        for(int i=2;i<=num;i++){
            int check=0;
            for(int j=2;j*j<=i;j+=2){
                if(i%j==0){check++;break;}
            }
            if(check==0)ans++;
        }
        cout<<ans<<endl;
    }
}

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

long long a[999999]={2,3,5};
int count=3;
long long maxc=6;
int main(){

	int t;
	while(cin>>t){

		if(t<maxc){
			int i=0;
			for(;a[i]<=t&&i<count;i++);
			cout<<i<<endl;
		}else{
			for(long long j=maxc;j<=t;j++){
				bool r=true;
				for(int i=0;i<count&&a[i]*a[i]<=j;i++){
					if(!(j%a[i]))
						r=false;
				}
				if(r)
					a[count++]=j;
			}
			maxc=t+1;
			cout<<count<<endl;
		}

	}

	return 0;
}

C++: #include <iostream>
#include <list>
#include <algorithm>
 
using namespace std;
 
int main() {
int n;
 
while(!cin.eof()) {
cin >> n;
list<int> search_list(n-1);
list<int> prime_number;
while(n!=1) {
search_list.push_front(n);
n--;
}
while(!search_list.empty()) {
int m = search_list.front();
prime_number.push_back(m);
search_list.pop_front();
list<int>::iterator it = search_list.begin();
while(it!=search_list.end()) {
if((*it % m) == 0){
it = search_list.erase(it);
continue;
}
it++;
}	
}
cout << prime_number.size()-1 << endl;
}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while (scanf ("%d",&n)!=EOF)
    {
    int prime[n+1],i,j;
    for (i=0;i<=n;i++)
        prime[i]=1;
    prime[0]=0;
    prime[1]=0;
    for (i=2;i<=sqrt(n);i++)
    {
        if (prime[i]==1)
        {
            for(j=2;i*j<=n;j++)
                prime[i*j]=0;
        }
    }
    int cnt=0;
    for (i=0;i<=n;i++)
    {
        if (prime[i]!=0)
            cnt++;
    }
    cout<<cnt<<endl;
    }
}