Go: package main
import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	//"math"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
	for sc.Scan(){
		n := nextInt()
		fmt.Println(calc(n))
	}
}

func calc(n int)int{
	// エラトステネスで数え上げる
	// 最初から999999まで用意しておいて入力のたびO(1)で出すのとどっちが速いのかはわからん
	eratos := make([]bool, n+1)
	c := 0
	for i:=2; i<len(eratos); i++{
		if eratos[i] == false{
			c++
			for j:=i*i; j<len(eratos); j+=i{
				eratos[j]=true
			}
		}
	}
	return c
}

func next()string{
	return sc.Text()
}

func nextInt()int{
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <iostream>

using namespace std;

int prime(int);

int main() {

	int n;

	while(cin >> n) {
		if(n>999999)
			continue;
		cout << prime(n) << endl;
	}

	return 0;

}

int prime(int n) {

	int i, j, k=0, count=0;
	if(n==0||n==1)
		return 0;

	for(i=2; i<=n; i++) {
		for(j=2; j<i; j++) { 
			if(i%j==0)
				k=1;
		}
		if(k==0)
			count++;
		k=0;
	}

	return count;

}

C++: #include <iostream>
using namespace std;
int main(){
	int n , i , j;
	while(cin >> n ){
		int counter = 0;
		for( int i=1 ; i<=n ; i++ ){
			if( i%2 == 0 ){
				continue ;
			}
			int x = i;
			if( i>=6 )
				x = x /2;
			int temple=0;
			for( int j=1 ; j<=x ; j++ ){
				if( i%j == 0 )
					temple++;
			}
			if( temple == 2 )
				counter ++;
		}
		cout << counter << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
long n,i,j,*nn;
for(;;){
cin>>n;
if(cin.eof())break;
nn=new long [n+1];
nn[1]=0;nn[2]=1;
for(i=3;i<=n;i+=2)nn[i]=1;
for(i=4;i<=n;i+=2)nn[i]=0;
for(i=3;i<=n;i+=2){
for(j=i;j*j<=n;j+=2){
if(i%j==0){nn[i]=0;break;}
}
}
cout<<j<<endl;
delete [] nn;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>

int main() {
	std::string line;
	while( std::getline( std::cin, line ) ) {
		int const num = std::atoi( line.c_str() );
		int result = num > 1 ? 1 : 0;	// 2
		
		for( int i=3; i<=num; i+=2 ) {
			if ( [&i]() -> bool
			{
				for( int j=3; j<=std::sqrt(i); j+=2 )
					if ( i % j == 0 )
						return false;
				return true;
			}() )
				++result;
		}
		std::cout << result << std::endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 10000000
bool prime[MAX-1];
int main(void){ 
  
  prime[0] = prime[1] = false;
  fill(prime,prime+MAX,true);

  int ans[1000000];
  
  ans[0] = ans[1] = 0;
  ans[2] = 1;
  for(int i = 2 ; MAX > i * i ; i ++){
    ans[i] = ans[i-1] + prime[i];
    if(prime[i]){
      for(int j = i + i ; MAX > j * j ; j += i){
	prime[j] = false;
      }
    }
  }
  
  //cout<<endl;
  //for(int i = 0 ; i < 10 ; i ++)cout<<ans[i]<<endl;
  //*/
  int n;
  while(cin>>n){
    //cout<<n<<" ";
    cout<<ans[n]<<endl;
  }
  //*/
}

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

static const long MAX = 1000000L;
 
int main() {
    vector<long> prime;
    bool isPrime;
    long ans = 0;
    long n;
 
    long i, len = sqrt(MAX) + 1;
    long j, lenJ;
    long k;
     
    prime.push_back(2);

    for (i = 3; i <= len; i += 2) {
        isPrime = true;
        lenJ = prime.size();
        k = sqrt(i) + 1;
        for (j = 0; j < lenJ; j++) {
            if (k <= prime[j]) break;

            if (i % prime[j] == 0) {
                isPrime = false;

                break;
            }
		}

        if (isPrime) prime.push_back(i);
    }

    lenJ = prime.size();
     
    while (cin >> n) {
        ans = 1;

        if (n < 2) ans = 0;
         
        for (i = 3; i <= n; i += 2) {
            isPrime = true;

            k = sqrt(i) + 1;
            for (j = 0; j < lenJ; j++) {
                if (k <= prime[j]) break;

                if (i % prime[j] == 0) {
                    isPrime = false;

                    break;
                }
            }

            if (isPrime) ans++;
        }
         
        cout << ans << endl;
    }
 
    return 0;
}

C++: #include<stdio.h>
#include<math.h>
#define ullint unsigned long long int

// ?????°???(a^b %d ????¨????)
int modpow(ullint a, ullint b, long int d) {
  if (b == 0)     return 1;
  if (b % 2 == 0) return modpow(a*a % d, b/2, d);
  else            return a*modpow(a, b-1, d) % d;
}

// Miller???Rabin?´???°?????????
bool Miller_Rabin_Test(int n){
    int prime_list[4] = {2, 7, 61};

    if(n == 2 || n == 7 || n == 61){  // 2,7,61????´???°
        return true;
    }
    if(n == 1 || n%2 == 0){  // 2??\????????¶??°??¨1????´???°??§??????
        return false;
    }
    // n = 2^s*d + 1 (d????\???°)?????¢????????¢
    int d = n-1;
    int s = 0;
    while(d%2 == 0){  // d????\???°??????????????§?????¢
        d = d/2;
        s++;
    }
    for(int i=0; i<3; i++){  // ??????????????????3???
        bool isProbPrime = false;
        int a = prime_list[i];
        int r = modpow(a, d, n);
        if(r == 1 || r == n-1){
            isProbPrime = true;
            continue;
        }
        for(int j=0; j<s; j++){
            r = modpow(a, pow(2,j)*d, n);
            if(r == n-1){
                isProbPrime = true;
                break;
            }
        }
        if(!isProbPrime){
            return false;
        }
    }
    return true;
}

int Primenum[1000000];

int main(){
    Primenum[1] = 0;
    for(int i=1; i<=1000000; i++){
        if(Miller_Rabin_Test(i)){
            Primenum[i] = Primenum[i-1] + 1;
        }else{
            Primenum[i] = Primenum[i-1];
        }
    }
    for(int n; scanf("%d\n",&n) != EOF;){
        printf("%d\n",Primenum[n]);
    }
    return 0;
}

C++: #include<cstdio>
using namespace std;
#define MAX_N 999999+10
int prime[MAX_N];
bool is_prime[MAX_N+1];

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(~scanf("%d",&n)){
        printf("%d\n",sieve(n));
    }
}

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

int main(void)
{
  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(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;
    }
  return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
using namespace std;

int main(){
  int n,i,j;
  while(cin >> n) {
    
    int k = 0, a[n];
    a[0] = 2;
  
    for (i = 3; i <= n; i++) {
      for (j = 0; j <= k; j++) {
        if(i % a[j] == 0) break;
      }
      if(j == k + 1) {
        k++;
        a[k] = i;
      }
    }
    for(i = 0; i <= k; i++) {
      cout << a[i] << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int a[1000000];
int sum[1000000];
int n;
int main(){
 for (int i=2;i<1000000;i++){
  if (!a[i])
   for (int j=i*2;j<1000000;j+=i)
    a[j]=1;
 }
 for (int i=2;i<1000000;i++) sum[i]=sum[i-1]+(a[i]==0?1:0);
 while (cin>>n)
  cout<<sum[n]<<endl;
 return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
long n,i,j,*nn;
for(;;){
cin>>n;
if(cin.eof())break;
nn=new long [n+1];
nn[1]=0;nn[2]=1;
for(i=3;i<=n;i+=2)nn[i]=1;
for(i=4;i<=n;i+=2)nn[i]=0;
for(i=3;i*i<=n;){
for(j=i;i*j<=n;j+=2)nn[i*j]=0;
i++;while(nn[i]==0)i++;
}
for(i=2,j=0;i<=n;i++)if(nn[i]==1)j++;
cout<<j<<endl;
delete [] nn;
}
return 0;
}