Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int sosuu(int n){
	int ans = 0;
	
	FOR(i, 2, n){
		if(i == 2){
			ans++;
		}else if(i % 2 != 0){
			bool flag = true;
			int j = 3;
			while(j * j <= i){
				if(i % j == 0){
					flag = false;
					break;
				}
				j += 2;
			}
			if(flag) ans++;
		}
	}
	return ans;
}
 
int main(){
    int n;
    while(cin >> n){
        cout << sosuu(n) << endl;   
    }	
}

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

void pr(int n){
    int ans=0;
    vector<bool> prime;
    for(int i=0;i<=n;i++){
        prime.push_back(true);
    }
    prime[0]=prime[1]=false;

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


int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        pr(n);
    }
    return 0;
}

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

using namespace std;

vector<int> ps;

int isprime(int n){
	vector<int>::iterator it;
	for(it=ps.begin();it!=ps.end();it++){
		if(n%(*it) == 0) return 0;
		if(n <= (*it)*(*it)) break;
	}
	ps.push_back(n);
	return 1;
}

int main(){
	int n;
	ps.push_back(2);
	while(scanf("%d", &n)!=EOF){

		int c=0;

		for(int i=3;i<=n;i++){
			if(i&1 && isprime(i)) c++;
		}

		printf("%d\n", c);
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    vector<int> primes;
    primes.PB(2);
    FOR(i,3,10000){
	bool flg = true;
	REP(j,primes.size()) if(i % primes[j] == 0 ) flg = false;
	if(flg) primes.PB(i);
    }

    int n;
    while(true){
	cin >> n;
	if(cin.eof())break;
	int res = upper_bound(ALL(primes),n) - primes.begin();
	cout << res << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define MAX_N 100001
int main(){
	int n;
	while(cin >> n){
		vector<int> vec;
		vector<int>::iterator it =vec.begin();
		for(int i=2;i<=n;i++){
			int flag=0;
			it =vec.begin();
			while(it!= vec.end()){
				if(i% *it==0){
					flag=1;
					break;
				}
				it++;
			}
			if(!flag)vec.push_back(i);
		}
		it =vec.begin();
		//while(it!= vec.end()){
		//	cout<<*it<<endl;
		//	it++;
		//}
		cout << vec.size()<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>

int main(){
 int i,j,n,count,flg;
 scanf("%d",&n);
 for(i=2,count=0;i<=n;i++){
  for(j=2,flg=1;j<=i/2;j++)
   if(i%j==0){ flg=0; break; }
  count+=flg;
 }
 printf("%d\n",count);
 return 0;
}

C++: #include <bits/stdc++.h>

#define MAX 1000000
#define NIL -1

int primes[MAX];

bool isPrime(int n)
{
    if (n <= 1) {
        primes[n] = 0;
        return false;
    }
    if (n <= 3) {
        primes[n] = 1;
        return true;
    }
    if (n % 2 == 0 || n % 3 == 0) {
        primes[n] = 0;
        return false;
    }
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0) {
            primes[n] = 0;
            return false;
    }
    primes[n] = 1;
    return true;
}

int main()
{
    for (int i = 1; i <= MAX; i++) primes[i] = NIL;
    int N, sum;
    while(std::scanf("%d", &N) != EOF) {
        sum = 0;
        for (int i = 2; i <= N; i++) {
            if (primes[i] != NIL) {
                if (primes[i] == 1) sum++;
            }
            else {
                if (isPrime(i)) sum++;
            }
        }
        std::printf("%d\n", sum);
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#define llint long long
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int pn = 0;
int p[1000000];
void getsosu(int Max) {
    for(int i = 2; i <= Max; i++) {
        bool flg = true;
        for(int j = 0; j < pn; j++) {
            if(p[j] * p[j] > i) break;
            if(i % p[j] == 0) {
                flg = false;
                break;
            }
        }
        if(flg) p[pn++] = i;
    }
}

int main() {
    getsosu(999999);

    int n;
    while(cin >> n) {
        int i = 0;
        while(p[i] <= n) i++;
        cout << i << endl;
    }
    return 0;
}

C++: <?php
$max=1000000;
$maxR=floor(sqrt($max));

$ch=[0,0,1,1];

for($i=4;$i<$max;$i+=2){$ch[]=0;$ch[]=1;}

for($i=3;$i<$maxR;$i+=2) if($ch[$i]) for($j=$i+$i;$j<$max;$j+=$i) $ch[$j]=0;

for($i=3;$i<$max;$i++) $ch[$i]+=$ch[$i-1];

while(fscanf(STDIN,"%d",$n)) printf("%d\n",$ch[$n]);

C++: #include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main(){
	int max = 1000000;
	bool is_prime[max] = {};
	for (int i = 2; i < max; ++i) {
		is_prime[i] = 1;
	}
	for (int i = 0; i < max; ++i) {
		if (is_prime[i]) {
			for (int j = i; j < max; j += i) {
				is_prime[j] = 0;
			}
		}
	}
	int num_prime[max] = {};
	for (int i = 1; i < max; ++i) {
		num_prime[i] = num_prime[i-1] + is_prime[i];
	}
	int n;
	while (cin >> n) {
		cout << num_prime[n] << endl;
	}
	return 0;
}

C++: 
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>

using namespace std;

int prime[999999];
bool is_prime[1000000];

int sieve(int n){
  int p=0;
  for(int i=0; i<=n; i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2; i<=n; i++){
    if(is_prime[i]){
      prime[p++]=i;
      for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
    }
  }
  return p;
}

int main(){

int n;

while(cin>>n){
  cout<<sieve(n)<<endl;
}

}

C++: #include<iostream>
#include<cmath>
#define MAX 1000000
using namespace std;
int main(){
	bool num[MAX] = {false,false};
	for(int i=2;i<MAX;i++){
		num[i] = true;
	}
	for(int i=2; i<sqrt(MAX); i++){
		if(num[i]){
			for(int l=i*2;l<MAX;l+=i){
				num[l] = false;
			}
		}
	}
	int n;
	while(cin >>n){
		int ans = 0;
		for(int i=0;i<=n;i++){
			if(num[i]){ans++;}
		}
		cout <<ans<<endl;
	}
	return 0;
}