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 <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <climits>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;

/*** typedef ***/
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ULL;
typedef pair < int , int > ii;
typedef pair < LL  , LL  > ll;
typedef vector <int>  vint;
typedef vector <bool> vbool;
typedef vector <long> vlong;

/*** define ***/
#define sz(x)			((int)x.size())
#define tin(x)			scanf("%d",&x)
#define all(x)			x.begin(),x.end()
#define Set(b,a)		memset(b,a,sizeof b)
#define print1(x)		printf("Case %d:",x++)
#define tin2(x,y)		scanf("%d%d",&x,&y)
#define tin3(x,y,z)		scanf("%d%d%d",&x,&y,&z)
#define loop(i,i0,in)	for(int i=i0 ; i<in ; i++)
#define rep(i,n)		for(int i=0 ; i<(n) ; i++)
#define _rep(i,n)		for(int i=n-1 ; i>=0 ; i--)
#define _loop(i,in,i0)	for(int i=in-1 ; i>=i0 ; i--)
#define Fore(it, x)		for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)

const int       maxn = 1000000+4;
const long double PI = 3.1415926535897932384626433832795;

int mp[maxn];
bool prime[maxn];

void sieve(int n){
	int cnt=0;
	Set(prime,0);
	prime[0]=prime[1]=1;
	loop(i,2,n){
		if(!prime[i]){
			mp[i]=++cnt;
			if(n/i>=i)
				for(int j=i*i ; j<=n ; j+=i)
					prime[j]=1;
		}
		else
			mp[i]=cnt;
	}
}

     
int main()  
{  
#ifdef Online_Judge
	freopen("a.in","r",stdin);
#endif
	int n;
	sieve(1000000);
	while(~tin(n))
		printf("%d\n",mp[n]);
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int count;
	while (1)
	{
		cin >> n;
		if (cin.fail()) break;

		bool *isPrime;
		isPrime = new bool[n + 1];
		memset(isPrime, true, sizeof(bool) * (n + 1));
		isPrime[0] = isPrime[1] = false;
		
		count = 0;
		for (int i = 2; i <= n; ++i)
		{
			for (int j = i + i; j <= n; j += i)
			{
				isPrime[j] = false;
			}
		}
		for (int i = 0; i <= n; ++i)
		{
			if (isPrime[i] == true)
				++count;
		}
		cout << count << endl;
		delete[] isPrime;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int x = 1000001;
	int p[x],q[x];
	for(int i=2;i<x;i++) p[i] = 0;
	for(int i=2;i<x;i++){
		if(q[i]==0) for(int j=2;j<x/i;j++) q[i*j] = 1;
	}
	int c = -1;
	for(int i=2;i<x;i++){
		if(q[i]==0){
			c++;
			p[c] = i;
		}
	}
	int n;
	while(cin >> n){
		int a = 0;
		for(int i=0;i<c;i++){
			if(p[i]>n) break;
			a++;
		}
		cout << a << endl;
	}
}

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

int main(){
  int n;
  int num[1000000]={0};
  num[0]=1;
  num[1]=1;

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

  while(scanf(" %d",&n)!=EOF){
    int cnt=0;
    for(int i=2;i<=n;i++){
      if(num[i]==0){
	cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;

C++: #include<stdio.h>

int main(){
	int n=0,i,g,count=0;
	bool p=false;
	while(scanf("%d",&n)){
	for(g=2;g<=n;g++){
		for(i=2;i<g;i++){
			if(g%i==0) p=true;
		}
		if(p) p=false;
		else{
			count++;
			p=false;
			}
		}
	printf("%d\n",count);
	count=0;
	}
	return 0;
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i*i <=MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i+i; j <=MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	int sum = 0;
	for (int i = 0; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}
	int n;
	while (cin >> n){
		cout << amount[n] << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  const double MAX = sqrt(99999);

  vector<int> preprime_list, prime_list;
  bool flag;

  for (int i = 2; i <= 99999; i++) {
    preprime_list.push_back(i);
  }

  while (preprime_list[0] < MAX) {
    for (int i = 1; i < preprime_list.size(); i++) {
      if (preprime_list[i]%preprime_list[0] == 0)
        preprime_list.erase(preprime_list.begin()+i);
    }
    prime_list.push_back(preprime_list[0]);
    preprime_list.erase(preprime_list.begin()+0);
  }
  prime_list.insert(prime_list.end(), preprime_list.begin(), preprime_list.end());

  int data,count;
  while (cin >> data) {
    for (int i = 0; i < prime_list.size() && prime_list[i] <= data; i++, count = i);
    cout << count << endl;
  }
}

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

int main(){
	bool *map;
	int n, cnt=0;

	cin >> n;
	map = new bool[n+1];
	for( int i=2; i<=n; i++ ){
		map[i] = true;
	}

	for( int i=2; i<=n/2; i++ ){
		for( int j=2*i; j<=n; j+=i ){
			if( map[j] ){
				map[j] = false;
			}
		}
	}

	for( int i=2; i<=n; i++ ){
		if( map[i] ){
			cnt++;
		}
	}
	cout << cnt << endl;

	delete[] map;
	map = 0;
}

C++: #include <iostream>
using namespace std;
int prime[10005]= {0};
int nprime=0;
void get_prime()
{
    for(int i=2; i<10005; i++)
    {
        if(!prime[i])
        {
            for(int j=i*i; j<10005; j+=i)

            {
                prime[j]=1;
            }
        }
    }
}
void print()
{
    for(int i=1; i<10005; i++)
    {
        if(prime[i]==0)
        {
            cout <<i << " ";

        }

    }
}
int main ()
{
    int n ;
    get_prime();
    while(cin >> n )
    {
        int sum =0;
        for(int i=2; i<=n; i++)
        {
            if(prime[i]==0)
            {
                sum ++ ;
            }
        }
         cout <<sum << endl ;

    }



//        print();
}

C++: #include<iostream>
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<String>
#include<time.h>
#include<math.h>

using namespace std;
int c = 0;
int i = 1;
unsigned long long a = 0;
unsigned long long b = 0;
unsigned long long sosuu[100000] = { 0 };
char fire = 0;
int pattara = 0;

int sub(int c) {

	
	
	/*while(i>-1)*/
	for (int i = 2; i<=c; i++){
		/*for (int z = 0; z < a;z++){*/
		for (int q = 1; q <= sqrt(i); q++) {
			sosuu[pattara] = i;
			if (sosuu[pattara] % 2 == 0 && sosuu[pattara]!= 2) {
				break;
			}
			if (sosuu[pattara] % q == 0) {
				b += 1;
			}

		}

		if (b == 1) {
			/*fire = _getch();*/
			pattara++;
			
		}
		b = 0;
		/*i++;*/
	}

	
	return 0;
}


int main(){
	while (scanf("%d", &c) != EOF){

		sub(c);
		cout << pattara << endl;
		pattara = 0;
		
	}

	return 0;
}