Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

C++: #include<iostream>
#include<math.h>
using namespace std;
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;
}
int main() {
  int n;
  int sum[1000000];
  sum[0]=0;
  sum[1]=0;
  sum[2]=1;
  for(int i=3;i<1000000;i++) {
    sum[i]=sum[i-1];
    if(IsPrime(i)) 
      sum[i]++;
 }
  while(cin>>n)
    cout<<sum[n]<<endl;
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool prime(int n)
{
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int main()
{
    int n,c,i;
    while(scanf("%d",&n)!=EOF)
    {
        c=0;
        for(i=2;i<=n;i++)
        {
            if(prime(i))
                c++;
        }
        cout<<c<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n,np[1000000];
bool isp[1000000];

int main()
{
    memset(isp,1,sizeof isp);
    isp[0]=isp[1]=0;
    for(int i=2;i<1000;i++)
        if (isp[i]) for(int j=i*i;j<1000000;j+=i) isp[j]=false;
    for(int i=1;i<1000000;i++) np[i]+=np[i-1]+isp[i];
    while (~scanf("%d",&n)) printf("%d\n",np[n]);
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while (1)
	{
		int tmp;

		cin >> tmp;

		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

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

		if (cin.eof()) { break; }
	}

	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>

using namespace std;

int main()
{
	int n;
	int len = 1;
	vector<int> prime;
	
	//unsigned long t = time(NULL);
	prime.push_back(2);
	for (int i = 3; i < 1000000; i += 2){
		int j;
		for (j = 0; j < len && prime[j] < i / 2; j++){
			if (i % prime[j] == 0){
				break;
			}
		}
		if (j >= len || prime[j] >= i / 2){
			prime.push_back(i);
			len++;
		}
	}
	//printf("%lu\n", time(NULL) - t);
	while (scanf("%d", &n) != EOF){
		int count;
		
		for (count = 0; prime[count] <= n; count++){//;
			//printf("%d\n", prime[count]);
			;
		}
		printf("%d\n", count);
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define N 999999L
bool num[N];

void furui(){
  long int i;
  int divide;
  int rt = (int) sqrt(N);
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for(divide = 2; divide <= rt; divide++){
    if(num[divide] == false) continue;
    for( i = divide; i < N; i+= divide){
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0; ;i++){
      c = getchar();
      if(c == EOF || c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == 1) count++;
    }
    std::cout << count << "\n";
    if(c == EOF) break;
  }
  return 0;
}

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

using namespace std;

#define maxn 999999 + 5
typedef long long ll;

int prime[maxn];

void init(){
    for(int i=2;i<maxn-4;i++)
        prime[i] = i % 2;
    prime[2]=1;
    prime[1]=0;
    for(int i=2;i*i<=maxn;i++){
        if(!prime[i])continue;
        for(int j=i;j*i<=maxn;j++)
            prime[i*j]=0;
    }
    for(int i=2;i<=maxn;i++)
        prime[i] += prime[i-1];
}
int main(){
    int n;
    init();
    
    while(~scanf("%d",&n))
        printf("%d\n",prime[n]);
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdio>

using namespace std;

bool isPrime(int x);

int main(void) {
	int n;
	while(scanf("%d", &n) != EOF) {
		
		int count = 0;
		for(int i = 1; i < n; i++) {
			if(isPrime(i))		count++;
		}
		
		cout << count << endl;
	}
	
	return 0;
}

bool isPrime(int x) {
	if(x < 2)			return false;
	else if(x == 2)		return true;
	
	if(x % 2 == 0)		return false;
	for(int i = 3; i * i <= x; i += 2) {
		if(x % i == 0)	return false;
	}
	return true;
}

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

int main(){
	int n,i,j,sqrtn,sum,flag;
	char number[1000000];
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;i++){
			number[i]=0;
		}
		sum=0;
		for(i=3;i<=n;i+=2){
			if (number[i]==1){
				continue;
			}
			sqrtn=(int)sqrt(i);
			flag=0;
			for(j=1;j*6-1<sqrtn;j++){
				if(i%(j*6+1)==0 || i%(j*6-1)==0){
					flag=1;
					break;
				}
			}
			if(flag==0){		/*ツ素ツ青板つカツづ。ツづ按つ「ツづ個づ可フツδ可グツづーツ猟ァツづづつュツづヲ*/
				sum++;
				for(j=i;j<n;j+=i){
					number[i]=1;
				}
			}
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

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

using namespace std;
int n;
int pr[170]={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};
bool prime(int x)
{
	int i;
	for(i=0;pr[i]*pr[i]<=x;i++)
	{
		if(x%pr[i]==0) 
		{
		 return false;
		}
	}
	return true; 
}

int main()
{
    while(cin>>n) {
        if(n==1) {
            printf("0\n");
            continue;
        }
        int ans=1;
        if(n==2) {
            printf("%d\n", ans);
            continue;
        }
        for(int i=3; i<=n; i+=2)
           if(prime(i)) ans++;
        printf("%d\n", ans);
    }
    return 0;
}