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 <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int n;

	while (cin >> n) {
		int counter = 0;
		
		if(n < 1000){
			for (int i = 2; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		}else if(n < 10000){
			counter = counter + 168;
			for (int i = 1000; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 100000){
			counter = counter + 1229;
			for (int i = 10000; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else {
			counter = counter + 9592;
			for (int i = 100000; i <= n; i++) {
				int kari = 1;
				for (int j = 2; j < i; j++) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		}
		cout << counter << endl;
	}

	return 0;
}

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

using namespace std;

int main(void){
	long n;
	int a;
	while(scanf("%d", &n) != EOF){
		bool p[1000001];
		for(int i = 2; i <= n; i++)
			p[i] = true;
		for(int i = 2; i < sqrt(n); i++){
			if(p[i]){
				for(int j = 0; i*(j+2) <= n; j++){
					p[i*(j+2)] = false;
				}
			}
		}
		int count = 0;
		for(int i = 2; i <= n; i++){
			if(p[i]) count++;
		}
		cout << count << endl;
	}
	return 0;
}

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


int main()
{

	int i,n,count;
	deque<int> sosu;
	while(cin >> n){
		if( n <= 2 ) {
			if( n == 2 ) {
				count = 1;
			}
			else 
				count = 0;
		}
		else {
			sosu.push_back(2);
			for( i = 3; i <= n ; i+=2 ) {
				bool flg = false;
				deque<int>::iterator it;
				for(it = sosu.begin(); it != sosu.end(); it++ ) {
					if( i % *it == 0 )
						break;
					if( i < 2 * (*it) ){
						flg = true;
						break;
					}
				}				
				if( flg == true ) {
					sosu.push_back( i );
				}
			}							
			count = sosu.size();
		}
		cout << count << endl;
	}
			
	return 0;
}

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


int main()
{

	int i,n,count;
	deque<int> sosu;
	while(cin >> n){
		sosu.clear();
		if( n <= 2 ) {
			if( n == 2 ) {
				count = 1;
			}
			else 
				count = 0;
		}
		else {
			sosu.push_back(2);
			deque<int>::iterator it;
			bool flg;
			for( i = 3; i <= n ; i+=2 ) {
				flg = false;	
				for(it = sosu.begin(); it != sosu.end(); it++ ) {
					if( i < 2 * (*it) ){
						flg = true;
						break;
					}
					if( i % *it == 0 )
						break;
				}				
				if( flg == true ) {
					sosu.push_back( i );
				}
			}							
			count = sosu.size();
		}
		cout << count << endl;
	}
			
	return 0;
}

C++: #include <cstdio>
#include <vector>

int main(int argc, char *argv[]) {
	using namespace std;
	
	int line;
	while (EOF != fscanf(stdin, "%d", &line)) {
		vector<bool> sieve(line, true);
		int prmCount = 0;

		for (int i = 2; i < line; i++) {
			if (sieve[i]) {
				prmCount++;
				for (int j = i+i; j < line; j+=i) {
					sieve[j] = false;
				}
			}
		}
		printf("%d\n", prmCount);
	}
	

	return 0;
}

C++: #include<stdio.h>
int main(void) {
   int n = 1000, i, l, s[1000];
   while ( n ) { s[n] = 0; n--; }
   s[1] = 1;
   for ( i = 2; i < 1000; i++ ) {
      if ( s[i] == 0 ) {
         for ( l = 2; l <= 1000 / i; l++ ) s[ i * l] = 1;
      }
   }
   for ( i = 1; i < 1000; i++ ) printf("s[%d]:%d\n", i, s[i]);
   return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
bool n[1000000]={0};
bool prime(int n){
	for(int i=2;i<=sqrt ((double)n);i++){
		if(n%i==0)return false;
	}
	return true;
}
int main(){
	for(int k=2;k<=999999;k++){
		if(prime(k))n[k]=true;
	}


	int a,sum=0;
	while(cin>>a){
	for(int j=2;j<=a;j++){
		if(n[j])sum++;
	}
	cout<<sum<<endl;
	sum=0;
	}
}

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

int main(){
	int n;
	int sosu[100000];
	int snum;
	bool judge;

	sosu[0] = 2;

	while(cin >> n){
		snum = 0;
		for(int i = 3; i <= n; i++){
			judge = true;
			for(int j = 0; j <= snum; j++){
				if(i%sosu[j] == 0){
					judge = false;
					break;
				}
			}
			if(judge == true){
				snum ++;
				sosu[snum] = i;
			}
		}
		cout << snum + 1 << endl;
	}



	return(0);
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,n;
    while ( cin >> a){
        n=0;
        for (int i=2;i<a;i++){
            if (prime(i)!=0){
                n++;
            }
        }
        cout << n << endl;
    }
}


int prime(int x){
    int y=0;
    if (x==1)
        return 1;
    for (int i=2;i<x/2+1;i++){
        if(x%i==0)
            return 0;
    }
    return x;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    vector<int> nl;
    int mx = 0;
    int n;
    while (scanf("%d ", &n) != EOF) {
        nl.push_back(n);
        mx = max(mx, n);
    }

    double r = sqrt(mx);

    list<int> sl;
    vector<int> primes;

    for (int i = 2; i <= mx; i++) {
        sl.push_back(i);
    }

    while (sl.front() <= r) {
        int p = sl.front();
        primes.push_back(p);
        sl.pop_front();

        auto i = sl.begin();
        while(i != sl.end()){
            if(*i % p == 0){
                i = sl.erase(i);
            }
            else {
                i++;
            }
        }
    }

    for (auto&& i : sl) {
        primes.push_back(i);
    }

    for (auto&& n : nl) {
        auto p = upper_bound(primes.begin(), primes.end(), n);
        printf("%d\n", p - primes.begin());
    }

    return 0;
}

C++: #include<stdio.h>
#include<float.h>
#include<vector>


vector<int> primes;
int ref_max=2;

int makePrimenumbers(int a){
	if(a<ref_max)return 0;

	temp = ref_max;
	ref_max=a;
	int i,k,isp=1;

	for(k=temp;k<ref_max;k++){
		for(i=0;i<primes.size();i++){
			if(k%primes[i]==0){
				isp=0;
				break;
			}
		}
		if(isp==1){
			primes.push_back(k);
		}
		isp=1;
	}
	return 0;
}

int countprime(int a){
	int i;
	for(i=0;i<prime.size();i++)
		if(a<prime[i])
			break;
	return (i);
}

int main(void)
{
	int result;
	while(scanf("%d",&a)!=EOF){
		makePrimenumbers(a);
		result = countprime(a);
		printf("%d\n",result);
	}
  return 0;
}

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

int main()
{
	int count=0,n;
	bitset<1000001> prime;

	prime[0]=1;
	prime[1]=1;
	for(int i=2;i<=1000;i++)
		if(prime[i]==0)
			for(int j=i+1;j<=1000000;j++)
				if(j%i==0)
					prime[j]=1;
	
	while(cin>>n)
	{
		for(int i=0;i<=n;i++)
			if(prime[i]==0)
				count++;
		cout<<count<<endl;
	}
		
}