Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n % i == 0 {
			return false
		}
	}
	return true
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
void init(bool* table){
	for (int i = 2; i < 100000; i++){
		for (int j = 2; j < 100000/i; j++){
			*(table + i*j) = false;
		}
	}
}
int main(){
	int num;
	bool table[100000];
	for (int i = 0; i < 100000; i++){
		table[i] = true;
	}
	init(table);
	while (cin >> num){
		int cnt = 0;
		for (int i = 2; i <= num; i++){
			if (table[i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//?????§??¬?´???°??¨????°???¬?????°
//O(1)?????????
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

#define NUM_MAX   1000010
bool flag[NUM_MAX];
vector< int >prm;

int N;
int ans = 0;
int K;

void eratosthenes(){
	if( N < 2 ) return;
	fill( flag, flag+NUM_MAX, 0 );
	int idx = 2;
	while( idx <= K ){
		while( flag[idx] ) idx++;
		if( idx > N ) break;
		//prm.push_back( idx );
		for( int i = idx; i <= N; i += idx ) flag[i] = 1;
		ans++;
	}
	while( idx < N ){
		idx++;
		if( !flag[idx] ){
			//prm.push_back( idx );
			ans++;
		}
	}
}


int main(){
	
	while( scanf("%d", &N) != EOF ){
		K = sqrt( N );
		K++;
		
		eratosthenes();
		
		cout<<ans<<endl;
		/*
		REP( i, prm.size() ){
			cout<<prm[i]<<endl;
		}*/
		//prm.clear();
		ans = 0;
	}	
	return 0;
	
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
while(cin >> n,!cin.eof()){
vector<int> prime;
prime.push_back(2);//ôðÈ­½ß2ÍÅÉüêÄ¨­
bool flag;
for(int x=3;x<=n;x+=2){
flag=true;
for(int y=0;prime[y]*prime[y]<=x;y++){
if(!(x%prime[y])){
flag=!flag;
break;
}
}
if(flag)prime.push_back(x);
}
int r = (n<=1)?(0):(prime.size());
cout << r << endl;
prime.clear();
}
return 0;
}

C++: #include<cstdio>
#include<string.h>
using namespace std;
int pNum;
bool IsPrime[1000010];
int Prime[1000010];
int GetPrime(int n){
    memset(IsPrime,true,sizeof(IsPrime));
    IsPrime[0]=IsPrime[1]=false;
    pNum=0;
    for(int i=2;i<=n;i++){
        if(IsPrime[i])Prime[++pNum]=i;
        for(int j=1;j<=pNum&&Prime[j]*i<=n;j++){
            IsPrime[Prime[j]*i]=false;
            if(i%Prime[j]==0)break;
        }
    }
    return pNum;
}
int main(){
    int n;
    while(scanf("%d",&n)){
        printf("%d\n",GetPrime(n));
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char const* argv[])
{
	bool flag[1000000];
	int p;

	for( int i = 0;i < 1000000;i++ ) flag[i] = true;

	for( int i = 2;i <= sqrt( 1000000 );i++ ){
		if( flag[i] != false ) for( int j = 2;j * i < 1000000;j++ ) flag[j * i] = false;
	}

	while( cin >> p ){
		int count = 0;
		for( int i = 2;i <= p;i++ ) if( flag[i] ) count++;
		cout << count << endl;
	}
}

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

void SieveOfEratosthenes(int n)
{
    int c = 0;
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (int p=2; p<=n; p++)
       if (prime[p]){
            c++;
       }

       cout<<c<<endl;

}

// Driver Program to test above function
int main()
{
    int n;
    while(cin>>n)
    {
        SieveOfEratosthenes(n);
    }

    return 0;
}

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	int i = 2;
	while (i <= num) {
		if (i == 2) {
			count++;
			i++;
			continue;
		}
		else if (i % 2 == 0) {
			//count++;
			i++;
			continue;
		}
		else {
			// Route Num?????´??°??¨??????????????????
			int routeN_int = (int)sqrt(i);
			int j = 3;
			while (1) {
				if (j > routeN_int) {
					count++;
					break;
				}
				if (i % j == 0) {
					break;
				}
				j += 2;
			}
		}
		i++;
	}


	return count;
}

int main() {

	int num = 0;
	while (cin >> num, num != 0) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}

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

bool IsPrime(int i){
    if(i < 2) return false;
    else if(i == 2) return true;
    else if(i % 2 == 0) return false;

    double sqrtNum = sqrt(i);
    for(int j = 3; j <= sqrtNum; j += 2){
        if(i % j == 0){
            return false;
        }
    }

    return true;
}

int main(){
    int n;
    while(cin >> n){
        int k = 0;
        for(int i = 0; i <= n; ++i){
           if(IsPrime(i) == true){
               k++;
           }else ;
        }
        cout << k << endl;
    }
}

C++: #include <iostream>

using namespace std;

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 0;
		if (cin.eof())
			return 0;
		//O(n)
		for (int i = 2; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

//O(sqrt(n))
bool isPrime(int x) {
	if (x % 2 == 0)
		return true;
	for (int j = 3; j * j <= x; j += 2) {
		if (x % j == 0)
			return false;
	}
	return true;
}

//SÌÆµÄAO(n*sqrt(n))
//ÚÀÆµÄAOÌàÌ®ª1000ÈºÈçÜ¸ÔÉ¤A1­Â´¦éÆÜ¸ÔÉíÈ¢
//O(100*1000)=10­A

C++: #include<iostream>
using namespace std;
int main(){
	int n,i,j,k,l,sum=0,num,SUM=0;
	for(i=0;i<30;i++){
		cin>>n;
		for(j=1;j<=n;j++){
			for(k=j;k>=1;k--){
				num=j/k*k;
				if(num==j)sum++;
			}
			if(sum==2)SUM++;
			sum=0;
		}
		cout<<SUM<<endl;
		SUM=0;
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>

int main()
{
    bool *table = new bool[1000000];
    while (true) {
        int n;
        std::cin >> n;
        if (std::cin.eof()) break;

        memset(table, 1, sizeof(bool) * (n + 1));
        for (int i = 2; i * i <= n; ++i)
            for (int j = 2; i * j <= n; ++j)
                table[i * j] = false;

        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += table[i];
        std::cout << cnt << std::endl;
    }
    delete[] table;
}

C++: #include <iostream>
using namespace std;
int main(){
	int a[100001] = {0};
	for(int i = 0; i < 100001; i++){
		a[i] = 1;
	}
	a[0] = 0;
	a[1] = 0;
	for(int i = 0; i < 100; i++){
		if(a[i]){
			for(int j = i * 2; j < 100001; j += i){
				a[j] = 0;
			}
		}
	}

	int n;
	while(cin >> n){
		int k = 0;
		for(int i = 0; i <= n; i++){
			if(a[i]) k++;
		}
		cout << k << endl;
	}

	return 0;
}