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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <limits>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
struct PrimeNumbers {
    vector<bool> sieve;
    vector<int> prime;
    PrimeNumbers(int n) : sieve(n+1,true) {
        sieve[0] = sieve[1] = false;
        for(long long i=2; i<sieve.size(); i++){
            if(sieve[i]){
                prime.push_back((int)i);
                for(long long j=i*i; j<sieve.size(); j+=i) {
                    sieve[j] = false;
                }
            }
        }
    }
    int size(void) { return (int)prime.size(); }
    int & operator [] (int n) { return prime[n]; }
    bool operator == (int n) { return sieve[n]; }
    bool operator != (int n) { return sieve[n]; }
};

int main() {

    int t;
    while(cin >> t) {
        PrimeNumbers p(t);
        cout << p.size() << endl;
    }
    return 0;
}

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

int arr[N];

void Eratosthenes(){
	for(int i = 0; i < N; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
	return;
}

int main(){
	int i,j=0,n,pn;
	while(cin>>n){
		pn=0;
		Eratosthenes();
		for(i=2 ; i<=n ; i++){
			if(arr[i]==1) pn++;
		}
		cout << pn << endl;
		
	}
	return 0;
}

C++: int main(){
int n;
while(cin >> n){
int a[n+1];
int b;
int c;
b=1;
while(b<n+1){
a[b]=0;
b=b+1;}
a[1]=1;
int d;
d=0;
b=2;
while(b<n+1){
if(a[b]==0){d=d+1; c=2; while(1){if(c*b>n){break;} a[c*b]=1; c=c+1;}}
b=b+1;}
cout << d;}

C++: #include<stdio.h>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    long int arr[999999];
    int p=0;
    int i,b,a;
    for(a=2;a<=999999;a++){

                b=0;
                for(i=2;i<=sqrt(a);i++){
                    if(a%i==0){
                    b=1;
                    break;
                    }
                }
                if(b==0){
                arr[p]=a;
                p++;
                }
            }
    int num,cot;
    while(scanf("%d",&num)!=EOF){
            cot=0;
            for(i=0;i<=999999;i++){
                if(arr[i]<=num)
                    cot++;
                else
                    break;
            }
            cout << cot << endl;
    }
    return 0;
}

C++: #include <iostream>

int main() {
    int n;
    while (std::cin >> n) {
        int primes = 0; // n以下の素数の数
        for (int i = 2; i <= n; i++) {
            bool flag = false; // はずれの目印
            for (int j = 2; j < i; j++)
                if (!(i % j)) {
                    flag = true;
                    break;
                }   
            if (!flag)
                 primes++;
        }
        std::cout << primes << std::endl;
     }   
}

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;
    prime_number.erase();
    search_list.erase();
  }
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

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( scanf("%d", &n) != EOF ) {

		int cnt = 0;
		for( int i = 2; i <= n; i++ )
			if( isPrime(i) )
				cnt ++;
		cout << cnt << endl;

	}

    return 0;
}

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

bool isPrime(int num) {
	if (num == 1)return false;
	if (num == 2)return true;

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


int main() {

	int num;
	int count;
	while (cin >> num) {
		count = 0;
		for (int i = 1; i <= num; i++) {
			if (isPrime(i))count++;
		}
		printf("%d\n", count);

	}

	//system("pause");
	return 0;
}

C++: #include<iostream>

using namespace std;

int isPrime(int n) {
  for(int i=2;i*i<=n;i++){
    if(n%i==0) return 0;
  }
  return 1;
}

int main() {
  int a;
  int b[1000000];
  for(int i=2;i<=1000000;i++){
    if(isPrime(i)) b[i]=b[i-1]+1;
    else b[i]=b[i-1];
  }
  while(cin>>a){
    cout << b[a] << endl;
  }
  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()
{
 int n, cnt;
 
 while(cin >> n)
 {
  cnt = 0;
  for(int i=2; i <= n; i++) {
   if(isPrime(i)) cnt++;
  }
  cout << cnt << endl;
 }
 return 0;
}

C++: #include<stdio.h>
int main ()
{
    int n,i,m,sum;
    while(1)
    {
        sum=0;
        scanf("%d",&n);
        for(m=2;m<=n;m++)
        {
            for(i=2;i<=m;i++)
            {
                if(m%i==0 && i<m)
                {
                    break;
                }
                if(i==m)
                {
                    sum=sum+1;
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}