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

using namespace std;

int SUUZI[1000000];

int a=0,b,d,f,n,c=0;
double buffer;

int main(){

	for(d=0;d<1000000;d++){SUUZI[d]=1;};
	
		for(a=3;a<1000000;a++){
			buffer=a;
				for(b=2;1;b++){
					if(a%b==0){SUUZI[a]=0;break;};
					if(b>sqrt(buffer)){SUUZI[a]=1;break;};
				};
};


while(cin>>n){
	c=0;
for(d=0;d<=n;d++){c+=SUUZI[d];};

cout<<c-2<<endl;

};
return 0;

}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;

const int SIZE = 1000001;
bool is_prime[1000001];
vector<int> primes;
int main()
{
	fill(is_prime, is_prime+SIZE, true);
	for (int i = 2; i < SIZE; ++i)
	{
		if (is_prime[i])
		{
			for (int j = 2*i; j < SIZE; j += i)
				is_prime[j] = false;
			primes.push_back(i);
		}
	}

	int n;
	while (scanf("%d", &n) != EOF)
		printf("%d\n", upper_bound(primes.begin(), primes.end(), n) - primes.begin() - 1);

	return 0;
}

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

constexpr int N = 999999;
vector<bool> primes( N+1, true );

void make_table() {
	primes[0] = false;
	primes[1] = false;

	int nr = (int)sqrt( N );
	for( int i = 2; i <= nr; ++i ) {
		if( primes[i] ) {
			for( int j = i+i; j <= N; j += i ) {
				primes[j] = false;
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio( false );

	make_table();

	int n;
	while( cin >> n ) {
		cout << count( primes.begin()+1, primes.begin()+1 + n, true ) << endl;
	}
}

C++: #include<stdio.h>
const int MAX_V=1000000;
int prime[MAX_V+1];
int sum[MAX_V+2];
int main(){
  int i,k,n;
  for(i=2;i<=MAX_V;i++){
    prime[i]=1;
  }
  for(i=2;i*i<=MAX_V;i++){
    if(prime[i]){
      for(k=2*i;k<=MAX_V;k+=i){
        prime[k]=0;
      }
    }
  }
  for(i=0;i<MAX_V+1;i++){
    sum[i+1]+=sum[i]+prime[i];
  }
  while(scanf("%d",&n)!=EOF){
    printf("%d\n",sum[n+1]);
  }
  return 0;
}

C++: #include	<stdio.h>

bool isPrimeNumber(int number){
	if(number	  == 2)	return true;
	if(number % 2 == 0)	return false;
	
	for(int i = 3; i * 2 <= number ;i += 2){
		if(number % i == 0)	return false;
	}
	return true;
}

int main(int argc, char** argv){
	
	int search, counter;
	
	while((scanf("%d", &search)) != EOF){
		counter = 0;
		for(int i = 2; i <= search; i++){
			counter += isPrimeNumber(i) ? 1 : 0;		
		}
		printf("%d\n", counter);
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll max_n = 1e6+4; 
void solve(){
    ll p = 0;
    ll Prime[n];
    ll isPrime[n+1];
    for(int i=0 ; i<=n ; i++){
        isPrime[i] = true;
    }
    isPrime[0] = isPrime[1] = 0;
    for(int i=2 ; i<=n ; i++){
        if(isPrime[i]){
            p++;
            for(int j=2*i ; j<=n ; j+=i){
                isPrime[j] = false;
            }
        }
    }
    cout << p << endl;
}

int main(){
    while (cin >> n, cin.eof() != true){
        solve();
    }
    return 0;
}

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, i;
	int a[10] = {0, 9592, 17984, 25997, 33860, 41538, 49098, 56543, 63951, 71274};
	while(cin >> n){
		i = 0;
		c = 0;
		for(int j = 900000; j >= 100000; j -= 100000){
			if(j < n){
				i = j+1;
				c = a[j/100000];
				break;
			}
		}
		
		for(; i <= n; i++){
			if(prime(i) == 1){
				c++;
			}
		}
		
		cout << c << endl;
	}
	
	return 0;
}

C++: #include<stdio.h>
#define MAX 1000010

int main(){
	bool prime[MAX];
	prime[0]=prime[1]=0;
	for(int i=0;i<MAX;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=2;i<MAX;i++){
		if(prime[i]==1){
			for(int j=2;i*j<MAX;j++){
				prime[i*j]=0;
			}
		}
	}
	int prime_under_num[MAX];
	prime_under_num[0]=0;
	for(int i=1;i<MAX;i++){
		prime_under_num[i]=prime_under_num[i-1]+prime[i];
	}
	
	int n;
	while((scanf("%d",&n))!=EOF){
		printf("%d",prime_under_num[n]);
	}
	
	
}

C++: #include <stdio.h>

int main(){
	int sosuu[1000000] = { 2, 3, 5 }, i,x,y=3,n;

	for (i = 3; i < 1000000; i+=2){
		for (x = 0; x < y;x++){
			if (i % sosuu[x] == 0){ break; }
			if (x+1 == y){ sosuu[y] = i, y++; }
		}
	}

	while (scanf("%d",&n)!= EOF){
		for (i = 0; i < y; i++){
			if (sosuu[i] < n + 1)break;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int cnt=0,res=0;
    for(int i=3; i<=n; i+=2){
      for(int j=1; j<=i; j++){
        if(i%j == 0) cnt++;
        if(cnt>2) break;
      }
      if(cnt==2) res++;
      cnt = 0;
    }
    cout << res+1 << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int prime[1000000];
int main(){
    int n,ans=0;
    for(int i=0;i<1000000;i++)
        prime[i]=1;
    prime[1]=0;
    prime[2]=1;
    for(int i=1;i<1001;i++){
        if(prime[i]==1){
            for(int j=i+1;j<1000000;j++){
                if(j%i==0)
                    prime[j]=0;
            }
        }
    }
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        if(prime[i]==1)
        ans++;
    }
    printf("%d",ans);
    return 0;
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

#define MAX 999999

using namespace std;

int main()
{
    int n;
    int num_prime[MAX];
    bool prime_flag[MAX];

    for (int i = 1; i < MAX; ++i) {
        if(!prime_flag[i]){
            for (int j = 2; (i+1)*j-1 < MAX; ++j) {
                prime_flag[(i+1)*j-1]= true;
            }
        }
        num_prime[i]=num_prime[i-1]+!prime_flag[i];
    }
    while (cin>>n){
        cout<<num_prime[n-1]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    while(cin >> n){
        bool prime[1000000] = {false};
        // falseで初期化
        prime[1] = true;
        prime[2] = false;
        int count = 0;
        
        // エラトステネスのふるい
        for(int j = 2; j * j <= n ; j++){
            if(!prime[j]){
                for (int k = 2; k*j <= n;k++){
                   prime[j*k] = true;
                }
            }
        }
        // falseだと素数
        for(int i = 1;i<=n;i++){
            if(!prime[i]) count = count +1;
        }
        cout << count << endl;
    }
    return 0;
}