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 <cmath>
//#include <ctime>
#define Even(n) n%2
using namespace std;

void count_Prime(int n);
bool IsPrime(int num);


int main()
{
	int Data = 0;
//	clock_t start, end;
	while (cin >> Data)
	{
//		start = clock();
		count_Prime(Data);
//		end = clock();

//		cout << (double)(end - start) / CLOCKS_PER_SEC << "sec" << endl;
	}

	return 0;
}

void count_Prime(int n)
{
	int counter = 0,  i = 0;
	for (i = 2; i <= n; ++i)
	{
		if (IsPrime(i))
			counter++;
	}

	cout << counter << endl;

}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

C++: #include<iostream>
#include <cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

////Nayeem Shahriar Joy,Applied Physics &Electronic Engineering,University of Rajshahi.

int main()

{
    bool prime[1000001];
    memset(prime,true,sizeof(prime));
    for( int i=4;i<=999999;i=i+2)
    {
        prime[i]=false;
    }
    for(int i=3;i*i<=999999;i++)
    {
        if(prime[i]==true){
        for(int j=i*2;j<=999999;j=j+i)
        {
            prime[j]=false;
        }
        }
    }
    int n;

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

C++: #include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	int a = 0;
	for(int i=2;i<=n;i++){
		bool x = true;
		for(int j=2;j<i;j++){
			if(i%j==0){
				x = false;
				break;
			}
		}
		if(x)
			a++;
	}
	cout << a << endl;
	return 0;
}

C++: #include <iostream>
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); 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を数えていない分
	return ct;
	//delete[] prime;
}

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

using namespace std;

#define N_MAX 1000000

int kouho[N_MAX / 2];

int main(){

	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/2; i < N_MAX / 2; i++){
			if ((kouho[i] % check) == 0){
				kouho[i] = 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;
	}

	

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

bool is_SPRP(uint32_t n, uint32_t a) {
  uint32_t d = n - 1, s = 0;
  while ((d & 1) == 0) {
    ++s;
    d >>= 1;
  }
  uint64_t cur = 1, pw = d;
  while (pw) {
    if (pw & 1) {
      cur = (cur * a) % n;
    }
    a = ((uint64_t)a * a) % n;
    pw >>= 1;
  }
  if (cur == 1) {
    return true;
  }
  for (uint32_t r = 0; r < s; r++) {
    if (cur == n - 1) {
      return true;
    }
    cur = (cur * cur) % n;
  }
  return false;
}

bool is_prime(uint32_t x) {
  if (x <= 1) return false;
  if (x < 1ULL << 32) {
    uint32_t bases[] = {2, 7, 61};
    for (uint32_t i = 0; i < sizeof(bases) / sizeof(bases[0]); ++i) {
      if (x != bases[i] && !is_SPRP(x, bases[i])) {
        return false;
      }
    }
    return true;
  }
}

int p[1000000];

int main() {
  int n;
  for (int i = 0; i < 1000000; ++i) {
    p[i] = is_prime(i);
  }
  for (int i = 1; i < 1000000; ++i) {
    p[i] += p[i - 1];
  }
  while (cin >> n) {
    cout << p[n] << endl;
  }
}

C++: #include <iostream>

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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	bool isprime[1000000];
  rep(i, 1000000) isprime[i] = true;
  isprime[0] = isprime[1] = false;
  FOR(i, 2, sqrt(1000000)) {
    if(isprime[i]) {
      ll j = i + i;
      while(j <= 1000000) {
        isprime[j] = false;
        j += i;
      }
    }
  }
  ll n;
  while(cin >> n) {
    ll cnt = 0;
    rep(i, n + 1) if(isprime[i]) cnt++;
    cout << cnt << endl;
  }
	return 0;
}

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


bool isPrime(int I)
{
	int b = sqrt (I*1.0) + 1;
	for(int i = 2; i < b; i ++){
		if(I % i == 0)
			return false;
	}
	return true;
}


int main(){
	int n;
	while(cin>>n){
		int total = 0;
		for(int i = 2; i <= n; i ++)
		{		
			if(isPrime(i) == true){
				total ++;
			}
		}
			cout<<total<<endl;
		}
	
}