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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

C++: #include<stdio.h>
#include<float.h>
#include<vector>



int makePrimenumbers(int a, int ref_max, vector<int> primes){
	int temp;
	
	if(a<ref_max)return 0;

	temp = ref_max;
	ref_max=a;
	int i,k,isp=1;

	for(k=temp;k<ref_max;k++){
		for(i=0;i<primes.size();i++){
			if(k%primes[i]==0){
				isp=0;
				break;
			}
		}
		if(isp==1){
			primes.push_back(k);
		}
		isp=1;
	}
	return 0;
}

int countprime(int a, voctor<int> primes){
	int i;
	for(i=0;i<prime.size();i++)
		if(a<prime[i])
			break;
	return (i);
}

int main(void)
{
	vector<int> primes;
	int ref_max=2;
	int result;
	int a;
	while(scanf("%d",&a)!=EOF){
		makePrimenumbers(a, max_ref, primes);
		result = countprime(a, primes);
		printf("%d\n",result);
	}
  return 0;
}

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

int main(void){
  int n;
  short int p[1000000];
  p[0] = p[1] = 0;
  p[2] = 1;
  int ans = 0;
  bool flag;
  for(int i = 3; i <= 1000000; i ++){
    if(i % 2 != 0){
      flag = true;
      for(int j = 3; j * j <= i; j += 2){
	if(i % j == 0){
	  flag = false;
	}
      }
      if(flag)
	ans++;
    }
    p[i] = ans;
  }
  // cout << "end" << endl;
  while(cin >> n){
    cout << p[n] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;
 
int main(){
int n,count,m_Prime;
 
while(cin >> n){
	int count = 0;
        int j=0;
        vector <int> array;
        
        for(int i=2;i<=n;i++){                  //探査配列の代入
                array.push_back(i);
                }
        
        while(m_Prime*m_Prime < n){
                m_Prime = 0;                                                    //m_Primeの初期化（最小を見つけたら素数探査から抜け出す為
                
                for(;j<=n-2;j++){                               //最小の素数を見つける。
                        while(array[j] == 0){j++;}
                        for(int k=2;k<=array[j];k++){					
                                if(array[j]%k==0 && array[j] != k)       break;
                                if(array[j] == k)       m_Prime = array[j];
                                
                                }
                        if(m_Prime != 0)        break;
                        }
                
                
                for(int l=0;l<=n-2;l++){                                //最小素数の倍数が入っている所を0にする。ただし、その数自体は放置
                        while(array[l] < m_Prime) {     l++;}
						if(array[l] == m_Prime) array[l] = 1;
                        if(array[l] % m_Prime == 0)     array[l] = 0;
                        }
               
                
                }
        
                
        for(int m=0;m<=n-2;m++){                                        //素数のカウント
                if(array[m]!=0) count++;
                }
        
        
        cout << count << endl;                                          //出力
        }
 
 
        
return 0;
}

C++: #include <stdio.h>

bool isPrime(int n);

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

bool isPrime(int n){
    if (n==1) return false;
    if (n==2) return true;
    for (int t=3; t*t<=n; t+=2){
        if (n%t == 0) return false;
    }
    return true;
}

C++: #include<stdio.h>
#include<math.h>
int main()
{ long long int LAST;
while(scanf("%lld",&LAST)==1){
long long  int num,i,count=0, is_prime;
for(num = 3; num <= LAST; num += 2)
{
is_prime = 1;
for(i = 2; is_prime && i <= num / 2; i++)
{
is_prime = (num % i != 0);
}
count += (is_prime ? 1 : 0);
}

printf("%lld\n",count+1);}
return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n, cnt;	
	while(cin >> n){
		bool prime[n] ={false};
		prime[1] = true;
		
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] = true;
				}
			}
		}
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std; 

int list[1000000]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,
 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,
 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757,
 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069};

long int a,b,loop,hasil,input,mid;
long int lo;
long int hi;

 bool Prima(unsigned long n) 
{
    for (unsigned short i = 0; list[i]*list[i] <= n; i++) 
	{
        if (n % list[i] == 0) 
		{
            return false;
        }
    }
 
    return true;
}

int main()
{
	lo=1087;
	a=180;
	while(lo<=1000003)
	{
		if(Prima(lo))
		{
			list[a]=lo;
			a++;
		}
		lo+=2;
	}
	//printf("%d",list[78498]);
	//while(scanf("%ld",&input)!= EOF)
	{	
	lo=0;
	while(input>=list[lo])
	{
		lo++;
	}
	printf("%d\n",lo);
	}
	return 0; 
}

C++: import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;;){
			if(!sc.hasNext())
				break;
			int n=sc.nextInt();
			int a=0;
			for(int i=2; i<=n; i++)
				if(isPrime(i))
					a++;
			println(""+a);
		}
		sc.close();
	}

	boolean isPrime(int n){
		int m=(int)sqrt(n);
		if(n==2)
			return true;
		if(n%2==0)
			return false;
		for(int i=3; i<=m; i++)
			if(n%i==0)
				return false;
		return true;
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}