Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2 || num == 5:
		return true
	case num < 2 || num%2 == 0 || num%5 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

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

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

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

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

int main(){
	int n;
	while ( cin >> n ){
		bool* table = new bool[ n + 1 ];
		for ( int i = 0; i <= n ; ++i ){
			table[ i ] = false;
		}
		if ( n >= 2 ) table[ 2 ] = true;

		for ( int i = 3; i <= n; i += 2 ){
			table[ i ] = true;
		}
		for ( int i = 3; i <= sqrt( static_cast< double >( n ) ); i += 2 ){
			if ( !table[ i ] ) continue;
			for ( int j = i + i; j <= n; j += i ){
				table[ j ] = false;
			}
		}

		int cnt = 0;
		for ( int i = 0; i <= n; ++i ){
			if ( table[ i ] ) ++cnt;
		}

		cout << cnt << endl;

		delete[] table;
	}
}

C++: #include <stdio.h>
const int MAX_V = 999999;
int main(){
int prime[MAX_V+1]={0};
int sum[MAX_V+2]={0};
int i, k, v ,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)){
    if(n==0)break;
     printf("%d\n" ,sum[n+1]);
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --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 all(a)  a.begin(), a.end()
using namespace std;

int main(){
  int n;
  while(cin >> n){
    int ans=1;
    int num[n+1]={0};
    for(int i = 3; i<=n; i+=2){
      bool isPrimeN = true;
      if(num[i]!=0) continue;
      for(int j=3; j<=floor(sqrt(i)); j++){
        if(i%j==0){
          isPrimeN = false;
          break;
        }
      }
      if(isPrimeN){
        for(int j=1; j<=n; j++){
          if(j*i > n) break;
          num[j*i]=1;
        }
        ans++;
      }
    }
    cout << ans << endl;;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int i,j,n;
	
	
	while(cin >> n){
	int count = 0;
	bool flag[n+1];
		
		for(i=2;i<n+1;i++) flag[i] = true;
		
		for(i=2;i<n+1;i++){
			if(!flag[i]){
				continue;
			}
			for(j=2*i;j<n+1;j+=i){
				flag[j] = false;
			}
		}
		
		// 個数を走査
		for(i=2;i<n+1;i++){
			if(flag[i]==true){
				count++;
			}
		}
		
		cout << count << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cmath>
#define Even(n) n%2
using namespace std;

void count_Prime(int n);
bool IsPrime(int num);


int main()
{
	int Data;

	while (cin >> Data)
	{
		count_Prime(Data);
	}

	return 0;
}

void count_Prime(int n)
{
	int counter = 0,  i = 0;
	for (i = 1; i <= n; ++i)
	{
		if (IsPrime(i))
			counter++;
	}

	cout << counter << endl;

}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

C++: #include <iostream>
using namespace std;
 
 
int main()
{
    int max = 10000;
    int prime[max];
    
    fill(prime, prime + max, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i < max; i++) {
        if (prime[i]) {
            for (int j = 2*i; j < max; j += i) {
                prime[j] = 0;
            }
        }
    }
    
    for(int i = 1;i < max; i++){
	    prime[i] = prime[i] + prime[i-1];
    }
    
    int aaa;
    while (cin >> aaa) {
	cout << prime[aaa] << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int pr[50847534];
int x = 0;

int nextpr(int p){
  int nxp = p+2;
  int i;
  int ok;
  x++;
  if(p==2)return 3;
  while(1){
      /*printf("p=%d->",nxp);*/
    for(i=0;pr[i]*pr[i]<=nxp;i++){
      ok = 1;
      if(!(nxp%pr[i])){
        ok = 0;
        break;
      }
    }
    if(ok){
        /*printf("O\n");*/
      return nxp;
    }else{
        /*printf("X\n");*/
      nxp+=2;
    }
  }
}

int main(){
    int n;
    int i;
    pr[0] = 2;
    while(scanf("%d",&n)!=EOF){
        printf("n=%d\n",n);
        i=0;
        if(n-1){
            while(pr[i]<=n){
                /*printf("prime:%d(%d)\n",pr[i],i+1);*/
                i++;
                if(i>=x){
                    pr[i] = nextpr(pr[i-1]);
                }
            }
        }
        printf("%d\n",i);
    }
}

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

const int INF = 1 << 30;
const int MAX_PRIME = 1000010;
bool is_prime[MAX_PRIME + 10];
vector<int> primes;

void init_primes() {
    fill(is_prime, is_prime + MAX_PRIME + 10, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=0; i<=MAX_PRIME; i++) {
        if(is_prime[i]) {
            primes.push_back(i);
            for(int k=i+i; k<=MAX_PRIME; k+=i) {
                is_prime[k] = false;
            }
        }
    }
}

int main() {
    init_primes();
    primes.push_back(INF);

    int N;
    while(scanf("%d", &N) != EOF) {
        printf("%zu\n", upper_bound(primes.begin(), primes.end(), N) - primes.begin());
    }
    return 0;
}

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

int prime[MAX];


int main(){
	prime[0]=1;
	prime[1]=1;
	prime[2]=0;
	prime[3]=0;
	for(int i=0;i*i<=MAX;i++) {
		if(prime[i]==1) continue;

		for(int t = i*2;t<MAX;t+=i)
			prime[i]=1;
	}

	while(cin.eof()){
		int m = 0;
		cin >> N;
		for(int i =0;i<=N;i++)
			if(prime[i]==0)
				m++;

		cout << m << endl;
	}

	return 0;
}

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

void pr( int [],int);
int main()
{   int n;  int counter; int *p;  int x=1;
const  int  m=100000;
 p=new int[1000000];
  pr(p,m);
	while(x<=30)
	{ counter=0;
	cin>>n;
	if(n<=999999)
	{
		for( int i=2; i<=n; i++)
		{
			if(*(p+i))
				counter++;
		}
		cout<<counter<<endl;
	}
	x++;
	}
	delete p;
}

void pr( int p[],int d )
{  
	*(p+0)=0; *(p+1)=0; bool flag;
	
	for(int i=2; i<d; i++)
	{
		flag=true;
		for(int j=2; j<i; j++)
		{
			if(i%j == 0)
			{
				flag=false;
				break;
			}
		}
		if(flag==true)
			*(p+i)=1;
		else
			*(p+i)=0;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define MAX (1000000)
int main(){
  vector<bool> isP(MAX,true);
  vector<int>  ans(MAX,0);
  int n;
  isP[0] = isP[1] = false;
  for(int i=2; i*i<MAX; i++)
    if(isP[i]){
      ans[i] = ans[i-1] + 1; 
      for(int j=i+i; j<MAX; j+=i)
	isP[j] = false;
    }else{
      ans[i] = ans[i-1];
    }
  
  while(cin>>n) cout<<ans[n]<<endl;
  return 0;
}