Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

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

int main(){
	const int max_num=3000000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
#define REP(i,n) for(unsigned int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define MAX 1000001
 
bool N[MAX] = {};
 
int M[MAX] = {};
 
void SoE()
{
    REP(i, MAX)N[i] = true;
 
    N[1] = true;
    for (unsigned int i = 2; i*i <= MAX; i++)
    {
        for (unsigned int j = i+i; j < MAX; j += i)
        {
            N[j] = false;
        }
    }
}
 
void Count()
{
    M[1] = 0;
    FOR(i, 2, MAX - 1)
    {
        int add = 0;
        if (N[i] == true)
        {
            add = 1;
        }
        M[i] = M[i - 1] + add;
    }
}
 
int main()
{
    SoE();
    Count();
    int tmp;
    while (cin >> tmp)
    {
        cout << M[tmp] << endl;
    }
    return 0;
}

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	bool *prime = new bool[n];
	//bool prime[999999];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= sqrt(n * 1.0); i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	delete[] prime;
	return ct;
}

C++: #include <iostream>

int PrimeNumberCount(int*, int);

const unsigned int MAX_NATURAL_NUMBER = 1000000;

int main(){
	int BoolPrimeNumber[MAX_NATURAL_NUMBER] = { 1, 1 };
	int NaturalNumber;
	for (int i = 2; i * i < MAX_NATURAL_NUMBER; ++i){
		if (!BoolPrimeNumber[i]){
			for (int j = i * 2; j < MAX_NATURAL_NUMBER; j += i){
				BoolPrimeNumber[j] = 1;
			}
		}
	}
	while (std::cin >> NaturalNumber){
		std::cout << PrimeNumberCount(BoolPrimeNumber, NaturalNumber) << std::endl;
	}
}

int PrimeNumberCount(int* BoolPrimeNumber, int NaturalNumber){
	int count = 0;
	for (int i = 2; i < NaturalNumber + 1; ++i){
		if (BoolPrimeNumber[i] == 0){
			++count;
		}
	}
	return count;
}

C++: #include <stdio.h>
#define false 0
#define true 1
 
int main(){
  char is_prime[1000000];
  int n;
  int n_prime[1000000];
 
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<1000000;i++){
    is_prime[i] = true;
  }
 
  for(int i=2;i*i<1000000;i++){
    if(is_prime[i]){
      for(int j=i*i;j<1000000;j=j+i){
        is_prime[j] = false;
      }
    }
  }
  int cnt = 0;
  for(int i=0;i<1000000;i++){
    if(is_prime[i]){
      cnt++;
    }
    n_prime[i] = cnt;
  }
 
  while(scanf("%d",&n) != EOF){
    printf("%d\n",n_prime[n]);
  }
 
  return 0;
}