Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n % i == 0 {
			return false
		}
	}
	return true
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

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

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 0;
		if (cin.eof())
			return 0;
		for (int i = 2; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

bool isPrime(int x) {
	if (x % 2 == 0)
		return true;
	for (int j = 3; j <= sqrt((double)x); j += 2) {
		if (x % j == 0)
			return false;
	}
	return true;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[999999]={0,0,1,2},n,k=0,count=2;
	for(int i=4;i<999999;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){k++;break;}
		}
		if(k==0)count++;
		a[i]=count;
		k=0;
	}
	while(cin>>n)cout<<a[n]<<endl;
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

int cntPrime(int n) {
  int cnt = 0, i, k;
  for(i = 2; i <= n; i++) {
    cnt += prime(i);
  }
  return cnt;
}

int main() {
  int a;
  int arg[1024] = { 0 };
  int cnt = 0;
  while(scanf("%d", &a) != EOF) {
    printf("%d\n", cntPrime(a));
  }
  int i;
  for(i = 0; i < cnt; i++) {
  }
}
~

C++: #include<stdio.h>
int flg[1000000];
int main(void)
{

	int a,i,j,cnt;
	while(scanf("%d",&a)!=EOF){	
		for(i=2;i<=a;i++){
		flg[i]=1;
		}
		for(i=2;i*i<=a;i++){
			if(flg[i]=1){
				j=2;
				while(i*j==a){
				flg[i*j]=0;
				j++;
				}
			}
		}
		cnt=0;
		for(i=2;i<=a;i++){
			if(flg[i]=1){
			cnt++;
			}
		}
		printf("%d\n",cnt);
	}	
	return 0;
}

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

bool IsPrime(int i){
    if(i < 2) return false;
    else if(i == 2) return true;
    else if(i % 2 == 0) return false;

    double sqrtNum = sqrt(i);
    for(int j = 3; j <= sqrtNum; j += 2){
        if(i % j == 0){
            return false;
        }
    }

    return true;
}

int main(){
    int n;
    while(cin >> n){
        int k = 0;
        for(int i = 0; i <= n; ++i){
           if(IsPrime(i) == true){
               k++;
           }else ;
        }
        cout << k << endl;
    }
}

C++: #include <stdio.h>
#include <algorithm>

using namespace std;

void set_prime_number(bool* array, int num) {

  fill(array, array + num, true);
  array[0] = array[1] = false;
  for (int i = 2; i < num; i++) {
    if (!array[i]) continue;
    for (int j = i * 2; j < num; j += i) {
      array[j] = false;
    }
  }

}

int main() {
  bool prime_number[1000000];
  int num;
  int nump=0;
  int cnt=0;

	while(scanf("%d",&num)!=EOF){
	  set_prime_number(prime_number,num);
	 for (int i = 0; i < num+1; i++) {
		 if (prime_number[i]){cnt++;}
	 }
	 printf("%d ",cnt);
	 cnt=0;
	}


  return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int a;
	int sum;
	while (cin >> a){
		sum = 0;
		for (int i = 0; i < a; i++){
			int y = 0;
			int l = i + 1;
			for (int i = 1; i != l+1; i++){
				if (l % i == 0) {
					y++;
				}
			}
			if (y == 2)sum++;
		}
		cout << sum << endl;
	}
}

C++: package util;
import java.util.Scanner;

public class Main{
    boolean isPrime[];

    void run(){
	isPrime = new boolean[1000000];
	for(int i=0;i<1000000;i++) isPrime[i] = true;

	isPrime[0] = false;
	isPrime[1] = false;

	for(int i=2;i<=1000000;i++){
	    if(!isPrime[i]) continue;
	    for(int j=i+i;j<=1000000;j+=i){
		isPrime[j] = false;
	    }
	}


	Scanner sc = new Scanner(System.in);
	while(sc.hasNext()){
	    int n=sc.nextInt();
	    int count = 0;
	    for(int i=0;i<=n;i++){
		if(isPrime[i]) count++;
	    }
	    System.out.println(count);
	}
    }

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

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
#include <string>
using namespace std;

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;
while(~scanf("%d",&n)){
int* table =  new int[n+1];
fill((int*)table,(int*)table+n+1,1);
table[0]=0;
table[1]=0;

for(int i=2;i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j+=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+n+1,1));
}
}

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(){
    int n;
    while(cin >> n){
        vector<int> prime;
        prime.push_back(2);

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

        cout << prime.size() << endl;
    }

    return 0;
}

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

int main(){
 int n,i,j,x,counter;
 while (cin >> n) {
  counter = 0;
  
  for (i = 1; i <= n; i++) {
    x = 0;
    
    for (j = 1; j <= i; j++) {
      if (i % j == 0) x++;
    }
    
    if (x == 2) counter++;
  }
  
  cout << counter << endl;
  
 }
 return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
	p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num){
	// num???????´???°?????°
	int count = 0;
	
	// Route Num?????´??°??¨??????????????????
	int routeN_int = (int)sqrt(num);
	//cout << routeN_int << endl;
	
	// ???n?????§?????´??°?????????????´???°????????°????????????
	vector<bool> prime_flag_set(num + 1, true);
	
	for(int i = 0; i < prime_flag_set.size(); i++){
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}
	//cout << endl;
	// 1???2 ?????? n ?????§?????´??°????????????p????????°????????? = false
	for(int p = 2; p < prime_flag_set.size(); p++){
		if( prime_flag_set[p] == false){
			continue;
		}
		int j = 2;
		// 3???2??????????????°?????????????????????p ??? ???n ????¶????????????????
		while(p < routeN_int){
			if(p*j > num+1){
				// num??\???
				break;
			}
			prime_flag_set[p * j] = false;
			//p????????°????±???????
			j++;
		}
	}
	// 2??\???
	for(int i = 2; i < prime_flag_set.size(); i++){
		if(prime_flag_set[i] == true){
			count++;
		};
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}
	
	return count;
}

int main(){
	
	int num = 0;
	while(cin >> num, num != 0){
		clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		clock_t end = clock();     // ????????????
    	std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}