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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> ll_i;
struct edge { int u, v; ll w; };

void sieve(int n, bool a[]) {
	fill(a, a + n, true);
	a[0] = a[1] = false;
	for (int i = 2; i * i < n; i++)
		if (a[i])
			for (int j = i * 2; j < n; j += i)
				a[j] = false;
}

bool a[1000000];
int b[1000000];

int main() {
	sieve(1000000, a);
	for (int i = 1; i < 1000000; i++)
		b[i] = b[i - 1] + (a[i] ? 1 : 0);
	int n;
	while (cin >> n) cout << b[n] << endl;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[9];
	a[0]=9592;
	a[1]=17984;
	a[2]=25997;
	a[3]=33860;
	a[4]=41538;
	a[5]=49098;
	a[6]=56543;
	a[7]=63951;
	a[8]=71274;
	while(cin>>n){
		int count=0;
		int i=0;
		while(true){
			if((i+1)*100000<=n)
				count=a[i];
			else
				break;
			i++;
		}
		if(n<100000){
			count=1;
			for(int j=3;j<=n;j++){
			bool t=false;
			for(int k=2;k<1+(double)sqrt((double)j);k++){
				if(j%k==0)
					t=true;
			}
			if(t==false)
				count++;
		    }
		}
		else{
		    for(int j=(i)*100000+1;j<=n;j++){
			    bool t=false;
			    for(int k=2;k<1+(double)sqrt((double)j);k++){
				    if(j%k==0)
				        t=true;
			    }
			    if(t==false)
				    count++;
		    }
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
int main()
{
  int i,j,cou=0,n;
  while(scanf("%d",&n)!=EOF){
    cou=0;
    for(i=2;i<=n;i++){
      if(i==2){
	cou++;
	continue;
      }
      for(j=2;j<i;j++){
	if(i%j==0)break;
	if(j==i-1)cou++;
      }
    }
    printf("%d\n",cou);
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,i,j;
  while(scanf("%d",&n)!=EOF){
    vector<int> v(1000000,0);
    for(i=2;i<n+1;i++){
      if(v[i])continue;
      for(j=2;i*j<n+1;j++)
	v[i*j]=1;
    }
    int sum=0;
    for(i=2;i<n+1;i++)
      if(v[i]==0)sum++;
    cout<<sum<<endl;
  }
}

C++: #include <iostream>

using namespace std;

int prime(int n)
{
	if(n < 2){
		return 0;
	} else if(n == 2){
		return 1;
	}
	
	if(n % 2 == 0){
		return 0;
	}
	
	for(int i = 3; i*i <= n; i+= 2){
		if(n % i == 0){
			return 0;
		}
	}
	
	return 1;
}

int main(int argc, char **argv)
{
	int n, c;
	
	while(cin >> n){
		c = 0;
		for(int i = 2; i <= n; i++){
			if(prime(i) == 1){
				c++;
			}
		}
		
		cout << c << endl;
	}
	
	return 0;
}

C++: #include<stdio.h>
int main(){
	int a,b,c,n;
	0<n<1000000;
	c=0;
	scanf("%d",&n);
	for(a=1;a<=n;a++){
		for(b=2;b<=n;b++){
			if(a%b==0&&a!=b){
				break;
			}else if(a%b==0&&a==b){
				c++;
			}else{
			}
		}
	}
	printf("%d\n",c);
	return 0;
}

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

#define max 1000000

int main(){
	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 + 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++: #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;
	int n;
	cin >> n;
	for (int i = 2; i<=n; i++){
		if (!vis[i]){
			
			prime[i] = 1;
			for (int j = i+i; j<=n; j += i){
				vis[j] = 1;
				prime[j] = 0;
				
		}
	}
	int sum = 0;
	for (int i = 2; i <= n; i++){
			if (prime[i]){
				sum++;
			}
		}
		cout << sum << endl;
	return 0;
}

C++: #include<iostream>

using namespace std;



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

int main()
{
	int n;
	while(cin>>n)
	{
		int count = 0;
		for(int i=0;i<=n;++i)
		{
			if(Prime(i))
			{
				++count;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
using namespace std;
typedef pair<int,int> P;
const int INF = (int)((unsigned int)-1>>1);


int main(){
    vector<int> prime;
    prime.push_back(2);

    for(int i=3;i<=999999;i+=2){
        bool is_prime = true;
        for(int j=0;j<prime.size();j++){
            if (prime[j]*prime[j] > i) break;
            if (i % prime[j] == 0){
                is_prime = false;
                break;
            }
        }
        if(is_prime){
            prime.push_back(i);
        }
    }

    int n;
    while(cin >> n){
        int ans = 0;
        for(int j=0;j<prime.size();j++){
            if (prime[j] > n) break;
            ans++;
        }
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt((long double)MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

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