Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
    int n;
    while (cin >> n)
    {
        int p[n + 1];
        for (int i = 0; i < n + 1; i++)
        {
            p[i] = 1;
        }
        p[0] = 0;
        p[1] = 0;
        for (int i = 2; i <= sqrt(n); i++)
        {
            for (int j = 2; i * j <= n; j++)
            {
                p[i * j] = 0;
            }
        }
        int c = 0;
        for (int i = 0; i <= n; i++)
        {
            if (p[i] == 1)
            {
                c++;
            }
        }
        cout << c << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int ar[1000009];
int pr[1000009];
int main()
{
    int i,n,j,k,z=2,te;
    for(i=4;i<=100009;i+=2){
        ar[i]=1;
    }

    pr[3]=1;
    int sq=sqrt(1000000)+3;
    for(i=3;i<=1000009;i+=2){

            if(ar[i]==0){pr[i+1]=z++;}
            if(i<=1000){
                if(ar[i]==0){
                    for(j=i*i;j<=1000009;j+=2*i){
                        ar[j]=1;
                    }
                }
            }
    }
    for(i=0;i<1000009;i++){
        if(pr[i]!=0){
            te=pr[i];
        }
        pr[i]=te;
    }




    while(scanf("%d",&n)==1){
            if(n>1){printf("%d\n",pr[n+1]);}
            else {
                printf("0\n");
            }
    }
    return 0;

}

C++: #include <cstdio>
#include <bitset>
using namespace std;
int c[999999]={0,1};
int main() {
	bitset<499999> b;
	int i,j,n=3;
	for(i=0;n*n<=999999;i++,n+=2) {
		if(b[i])continue;
		for(j=i+n;j<499999;j+=n)b[j]=1;
	}
	for(i=0,n=3;i<=499998;i++,n+=2) {
		if(!b[i])c[n-1]=c[n]=c[n-2]+1;
		else c[n-1]=c[n]=c[n-2];
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",c[n-1]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define MAX 1000000
#define LMT 1000
unsigned flag[MAX>>6];
int primes[6000000];//5761455
#define ifc(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define isc(n) (flag[n>>6]|=(1<<((n>>1)&31)))

int sieve()
{
    unsigned i, j, k;
    for(i=3; i<LMT; i+=2)
        if(!ifc(i))
            for(j=i*i, k=i<<1; j<MAX; j+=k)
                isc(j);
    return 0;
}

int main()
{
    sieve();
    unsigned int i,L;
    int k=1, count;
    primes[0]=2;
    while(scanf("%d", &L)==1)
    {
        count=1;
        for( i=3; i<=L; i+=2)
        {
            if(ifc(i)==0)
                count++;
        }
        if(L>1)
            printf("%d\n", count);
        else printf("0\n");
    }
    return 0;
}

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

int main(void)
{
    int count=0;
    int i=1;
    int n=1;
    int number;
    // insert code here...
    while (cin >> number, number != EOF){
        while (n <= number){
            if(n == 1) {n++; continue;}
            while (i <= n) {
                if(i == 1) {i++; continue;}
                if(i == n) count++;
                if(n % i == 0) break;
                i++;
            }
            n++;
            i=1;
        }
        i=1;
        n=1;
        cout << count << endl;
        count = 0;
    }
    return 0;
}

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

bool isprime(int q){
	if(q==2)return true;
	if(q%2==0)return false;
	int max=sqrt(q);
	for(int i=3;i<q;i=i+2){
		if(q%i==0)return false;
	}
	return true;
}

int main(){
	int n;
	while(cin>>n){
		int sum=0;
		for(int i=2;i<=n;i++){
			if(isprime(i))sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}

C++: #include <iostream>

#define N 1000000

using namespace std;

int main() {
	bool prime[N];
	prime[0] = prime[1] = false;

	//initialize
	for(int i=2; i<N; i++) prime[i] = true;
	cout<<"End Initialize prime array!"<<endl;
	//Sieve of Eratosthenes
	for(int i=2; i<=N/2; i++){
		if(prime[i]){
			for(int j=2; i*j<=N; j++)
			{
				prime[i*j] = false;
			}
		}
	}
	cout<<"End Sieve of Eratosthenes"<<endl;

	int countPrime[N];
	int cnt = 0;
	for(int i=0; i<N; i++){
		if(prime[i]){
			cnt++;
		}
		countPrime[i] = cnt;
	}

	int input;
	while(true) {
		cin>>input;
		if(cin.eof()){break;}
		cout<<countPrime[input]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
 int n, i, j, k;
 int b;
 int count = 0;
 
 

 while(cin >> n){
  int a[n+1];
  for(i = 2;i < n+1;i++){
    a[i] = i;
  }


  for(i = 2;i*i < n;i++){
    if(a[i] != 0){
      b = a[i];
     }
    for(j = 2;j*b < n+1;j++){
      a[j*b] = 0;
    }
  }
  for(i = 2;i < n+1;i++){
    if(a[i] != 0){
      count++; 
    }
  }
  cout << count << endl;
  count = 0;
  
  
 }

 return 0; 
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

bool isprime(int n){
  if(n==2||n==3) return true;
  for(int i=2; i*i<=n; i++) if(n%i==0) return false;
  
  return true;
}

bool prime[1000005]={true};

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; continue;}
    for(int i=2; i<=n; i++) prime[i]=true;
    int ans=0;
    for(int i=2; i<=n; i++){
      if(isprime(i)&&prime[i]) {
        ans++;
        for(int j=2*i; j<=n; j+=i) prime[j]=false;
      }
    }
    cout<<ans<<en;
  }
}

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

bool isPrime(unsigned int n) {
  unsigned int count=0;
  count = 0;

  if(n==2) return true;
  if(n%2==0) return false;

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

int main() {
  unsigned int input;
  unsigned int count;
  
  while(cin >> input) {
    count = 0;
    unsigned int i = 2;
    for(int i=2;i<=input;i++) {
      if(isPrime(i))
        count++;
    }
    cout << count << endl;
  }
  return 0;
}

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

int main(void){
int unti[100002] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
	if((a * n  ) < 100001 ) unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
}
return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main()
{
	int a = 0, b = 0;
	while (cin >> a)
	{
		b = 0;
		for (int i = 2; i <= a; i++)
		{
			int c = 0;
			for (int j = 2; j < i; j++)
			{
				if (i % j == 0)
				{
					c = 1;
				}
			}
			if (c == 0)
			{
				b++;
			}
		}
		cout << b << endl;
	}
	
	return 0;
}