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:
		return true
	case num < 2 || num%2 == 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 <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)

int main()
{
	int n;
	int c;

	while(cin >> n) {
		c = 0;

		vector<int> P(n);
		REP(i, n) P[i] = 1;

		P[0] = 0;

		for(int i = 1; i * i < n; ++i) {
			if(P[i] == 1) {
				for(int j = i + 1; j * (i + 1) - 1 < n; ++j) {
					P[j * (i + 1) - 1] = 0;
				}
			}
		}

		REP(i, n) {
			if(P[i] == 1)
				++c;
		}

		cout << c << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp;
	
	
//	vector<int> isPrime;
	bool isPrime[1000000];
	
	while(cin>>n)
	{
		for(int i = 0; i < n; i++){
//			isPrime.push_back(1);
			isPrime[i] = 1;
		}
//		cout << "Corecced!" << endl;
		isPrime[0] = isPrime[1] = 0;
		temp = 0;
		
		for(;;)
		{
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i*head < n; i++){
				isPrime[i*head] = 0;
			}
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
		//	printf("head:%d    fin:%d\n",head,fin);
			
			if(fin <= head*head){
				break;
			}
			temp = head;
		}
		
		int cont = 0;
		for(int i = 0; i < n; i++){
			if(isPrime[i] == 1){
				cont++;
		//		cout << "+"<<i << endl;
			}
		}
		printf("%d\n",cont);
	}
}

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

int ans ;
int N ;
bool prime[1000200] ;

void SE ( ) ;

int main ( ) 
{
	memset ( prime , false , sizeof ( prime ) ) ;
	SE ( ) ;
	while ( scanf ( "%d" , &N ) == 1 ) {
		ans = 0 ;
		if ( N >= 2 ) {
			ans++ ;
		}
		for ( int i = 3 ; i <= N ; i += 2 ) {
			if ( prime[i] == false ) {
				ans++ ;
			}
		}
		printf ( "%d\n" , ans ) ;
	}
	return 0 ;
}

void SE ( )
{
	prime[0] = prime[1] = true ;
	for ( int i = 3 ; i < 1004 ; i += 2 ) {
		if ( prime[i] == false ) {
			for ( int j = i * i ; j < 1000200 ; j += i * 2 ) {
				prime[j] = true ;
			}
		}
	}
}

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

int whether(int num);
int count(int num);

int main(){
	int n;
	int a;

	while(1){
		if(feof(stdin)==EOF) break;
		scanf("%d",&n);
		a = count(n);
		printf("%d\n",a); 
	}

	return 0;
}

int whether(int num){
	int s=sqrt(num);
	int i;
	for(i=3; i<=s; i+=2){ if(num%i==0) return 0; }

	return 1;
}

int count(int num){
	int a=1;
	int i;
	if(num <2){ return 0; }
	for(i=3; i<=num; i+=2){
		a += whether(i);
	}

	return a;
}

C++: #include <iostream>
#include <list>
#include <algorithm>

int main(){
	int NUM;
	while(std::cin >> NUM){
		std::list<int> numList,primeList;
		for(int i=2;i<=NUM;++i){
			numList.push_back(i);
		}
		for(int i=numList.front();i*i<NUM;i=numList.front()){
			primeList.push_back(i);
			numList.erase(std::remove_if(numList.begin(),numList.end(),[&](int num){return num%i==0;}),numList.end());
		}
		int cnt=numList.size()+primeList.size();	
		std::cout << cnt << std::endl;
		}
	return 0;
}

C++: #include <memory.h>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int i;
	int pos;
	int val;
	int target;
	int sosuList[78499];

	memset(sosuList, 0, sizeof(sosuList));

	sosuList[0] = 2;
	sosuList[1] = 3;
	sosuList[2] = 5;
	sosuList[3] = 7;
	sosuList[4] = 11;

	while (cin >> target) {
		for (pos = 0; sosuList[pos] != 0; pos++) {
			if (sosuList[pos] > target) break;
		}
		for (val = sosuList[pos - 1] + 1 ; val <= target ; val++) {
			for (i = 0; i < pos - 1 ; i++) {
				if (sosuList[i] * 2 > val) { i = pos; break; }
				if (val % sosuList[i] == 0) break;
			}
			if (i >= pos - 1) sosuList[pos++] = val;
		}
		cout << pos << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

bool isprime[1000000];

void solve(int n) {
    int cnt = 0;
    for (int i = 2; i <= n ; ++i) {
        if(isprime[i]) {
            cnt++;
            for (int j = i*2; j <=n ; j = j + i) {
                isprime[j] = false;
            }
        }
    }
    cout << cnt << endl;
}

int main() {
    int n;
    while(cin>>n) {
        for (int i = 0; i <= n; ++i) {
            isprime[i] = true;
        }
        isprime[0] = isprime[1] = false;
        solve(n);
    }


    return 0;
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int list[100000];

    cnt=0;
    for (long i=2; i<1000000; i++){
	//    printf("%d %d\n",i, cnt);
        if (i%10==0) list[i/10] = cnt;
        cnt += IsPrime(i);
    }
	printf("input : ");
    while (scanf("%d", &n) && n!=EOF){
        cnt = list[n/10];
        for (long i=1; i<n%10; i++){
            cnt += IsPrime(i);
        }
        printf("%d\n", cnt);
    }
    return 0;
}

int IsPrime(int n){
    int i;

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

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

int main()
{
	int n;
	const int MAX = 1000000;
	int primecount[MAX];

	for (int i = 2; i < MAX; i++) {
		primecount[i] = 1;
	}

	for (int i = 2; i < MAX; i++) {
		if (primecount[i] == 1) {
			for (int j = i * 2; i < MAX; j += i) {
				primecount[j] = 0;
			}
		}
	}

	for (int i = 1; i < MAX; i++) {
		primecount[i] += primecount[i - 1];
	}

	short i = 1;

	while (cin >> n && i <= 30) {
		cout << primecount[n] << endl;
		i++;
	}

	return 0;
}

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

int main(){
	const int max_num=1100000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={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 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}