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++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
    memset(vis, 0, sizeof(vis));
    memset(prime, 0, sizeof(prime));
    prime[0] = prime[1] = 0;
     
    for (int i = 2; i*i <=MAX; i++){
        if (!vis[i]){
            prime[i] = 1;
            for (int j = i+i; j <=MAX; j += i){
                vis[j] = 1;
                prime[j] = 0;
            }
        }
    }
    /*int sum = 0;
    for (int i = 2; i <= MAX; i++){
        if (prime[i]){
            sum++;
        }
        amount[i] = sum;
    }*/
    int n;
     
    while (cin >> n){
        int sum = 0;
        for (int i = 2; i <= n; i++){
            if (prime[i]){
                sum++;
            }
        }
        cout << sum << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int prime[N], cnt;bool st[N];
void init() {
    st[0] = st[1] = true;
    for(int i = 2; i < N; i++) {
        if(!st[i])  prime[cnt++] = i;
        for(int j = 0; j < cnt && i * prime[j] < N; j++) {
            st[i * prime[j]] = true;
            if(i % prime[j] == 0)   break;
        }
    }
}
int main() {
    init();
    int n, sum;
    while(cin >> n) {
        sum = 0;
        for(int i = 2; i <= n; i++)
            if(!st[i])
                sum++;
        cout << sum << endl;
    }
}

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

bool IsPrime(int m){
    if(m==1){
        return(1);
    }else if(m==2){
        return(1);
    }else if(m%2==0){
        return(0);
    }else{
        for(int i=3;i*i<=m;i+=2){
            if(m%i==0)return(0);
        }
        return(1);
    }
}
int main(){
    int n;
    int r[30];
    for(int i=0;i<30;i++){
        r[i]=0;
    }
    int j=0;
    while(n!=0){
        cin>>n;
        for(int i=1;i<=n;i++){
            if(IsPrime(i))r[j]++;
        }
        cout<<r[j]<<endl;
        j++;
    }
    return(0);
}

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


using namespace std;



bool isPrime(int num) {
	if (num < 2)return false;
	if (num == 2)return true;
	if (num % 2 == 0)return false;
	int root = (int)sqrt(num);
	for (int i = 3; i <= root; i += 2) {
		if (num % i == 0)return false;
	}
	return true;
}

int main() {

	int num;
	while (cin >> num) {
		int count = 0;
		for (int i = 2; i <= num; i++) {
			if (isPrime(i))count++;
		}
		cout << count << endl;
	}


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

C++: #include<iostream>
#include<sstream>
#include<cstdio>
#include<fstream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;

#define ull unsigned long long
ull power(ull b,ull e,ull p){
	ull ret = 1;
	while(e>0){
		if((e&1)!=0){
			ret = (ret*b)%p;
		}
		b = (b*b)%p;
		e>>=1;
	}
	return ret%p;
}

bool fermat(ull p){
	if(p!=2 && p%2==0)return false;
	if(p!=3 && p%3==0)return false;
	if(p!=5 && p%5==0)return false;
	if(p!=7 && p%7==0)return false;
	for(int x=0;x<100;++x){
		ull a = rand()%(p-1)+1;
		if(power(a,p-1,p)!=1)return false;
	}	
	return true;
}

int main(){
	int n;
	while(scanf("%d",&n)==1){
		int tot = 0;
		for(int x=2;x<=n;++x){
			if(fermat(x))++tot;
		}
		cout<<tot<<endl;
	}
	return 0;
}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
	int a[1000000];
	a[0]=2;
	int z=1;
	for(int i=2;i<100000;){
		for(int j=0;j<z;j++){
			if(i%a[j]==0)goto stop;
		}
		a[z]=i;
		z++;
		stop:;
		if(i==2) i++;
		else i+=2;
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=0;i<z;i++){
			if(a[i]>b)break;
			else c++;
		}
		cout<<c<<endl;
	}
}

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

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

int main(void) {
    int num;
   
    while(cin >> num) {
        int prime[num + 1];
        memset(prime, -1, sizeof(prime));
        prime[0] = prime[1] = 0;
        int sum = 1;
        
        for(int r = 3; r <= num; r += 2) {
            if(prime[r] != -1) continue;
            if(isPrime(r)) {
                prime[r] = 1;
                sum++;
                for(int c = 2 * r; c <= num; c += r) prime[c] = 0;
            }
        }
        
        cout << sum << endl;
    }
}

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

int main()
{
	const int N = 1000000;
	vector<bool> vec(N, true);
	double limit = sqrt(N);
	for (int i = 2; i < limit; i++){
		for (int j = 2; i * j < N; j++){
			vec[i * j] = false;
		}
	}
	int n, cnt = 0;
	while (cin >> n){
		for (int i = 2; i <= n; i++){
			if (vec[i])cnt++;
		}
		cout << cnt << endl;
		cnt = 0;
	}
}

C++: #include<iostream>
int fact(int x){
	int sx=0,sy=0;
	for(int i=2;i<x+1;i++){
		if(x%i==0)sx++,sy+=i;
	}
	if(sx==1)return x;
	else return sy+1;
}
int main(){
	int a;
	while(std::cin>>a){
		int n=0;
		for(int i=2;i<a+1;i++){
			if(i==fact(i))n++;
		}
		std::cout<<n<<std::endl;
	}
	
	return 0;
}

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

bool prime(int n) {
	for(int i=2;i<=sqrt(n);++i) {
		if(n%i==0) { return false; }
	}
	return true;
}

int main() {
	int n;
	while(scanf("%d",&n) != EOF) {
		int cnt=0;
		for(int i=2;i<=n;++i) {
			if(prime(i)) { ++cnt; } 
		}
		printf("%d\n",cnt);
	}
	return 0;
}

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

int main(void) {
  int n, *ar, *sum, i, j;
  if((ar = (int*)malloc(sizeof(int) * 1000000)) == NULL) return 1;
  if((sum = (int*)malloc(sizeof(int) * 1000000)) == NULL) return 1;
  for(i = 1; i < 1000000; ++i) ar[i] = 1, sum[i] = 1;
  for(i = 2; i < 1000; ++i) {
    if(ar[i]) for(j = 2; i * j < 1000000; ++j) ar[i * j] = 0;
  }
  for(i = 2; i < 1000000; ++i) sum[i] = sum[i - 1] + ar[i];
  while(scanf("%d", &n) != EOF) {
    printf("%d\n", sum[n]);
  }
  free(ar);
  free(sum);
  return 0;
}

C++: //
//  main.cpp
//  TestCpp
//
//  Created by Shahab Uddin on 05/21/13.
//  Copyright (c) 2013 ___Shahab__. All rights reserved.
//

#include <cstdio>
#include <cmath>

bool isPrime (int p)
{
    if ( p < 2 ) return false;

    if ( p == 2 ) return true;

    int squareRoot = (int) sqrt (p);

    for ( int i = 2; i <= squareRoot; i++ ) {
        if ( p % i == 0 )
            return false;
    }

    return true;
}

int main(int argc, const char * argv[])
{
    int n;

    while ( scanf ("%d", &n) != EOF ) {
        int ans = 0;

        for ( int i = 2; i < n; i++ ) {
            if (isPrime(i)) ans++;
        }

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

    return 0;
}

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

int main(){
	int n;
	int a=0;
	cin >> n;
		for(int i = 0; i < n; ++i){
			for(int j = 2; j <= i; ++j){

				if(i%j == 0){
				if(i==j){
					++a;
				}else{
					break;
				}
				}
		}
	
	}
		cout << a << '\n';
}