Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

int main(){
    vector<int> prime;
    int n;
    for(int i=2;i<1000000;i++){
        bool isprime=true;
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0){
                isprime=false;
                break;
            }
        }
        if(isprime) prime.push_back(i);
    }
    while(cin >> n){
        for(int i=0;i<prime.size();i++){
            if(prime[i]>n){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main(){
  int n, count,j;
  int limit;
  vector<int> nl;
  while(cin >> n){
    nl.push_back(n);
  }

  for(int i=0; i<nl.size(); i++){
    n = nl[i];
    int prime[n+1];
    for(j=2; j<=n; j++){
      prime[j] = 1;
    }
    count = 0;
    limit = (int)sqrt(n);
    for(j=2; j<=limit; j++){
      if(prime[j] == 1){
        for(int k=j*2; k<=n; k+=j){
          prime[k] = 0;
        }
      } 
    }

    for(j=2; j<=n; j++){
      if(prime[j]==1){
        count++;
      }
    }
    cout << count << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isprime(int n) {
	if (n == 2)return true;
	for (int i = 3; i <= sqrt(n); i += 2) if (n%i == 0)return false;
	return true;
}
int main() {
	long long n;
	while(cin >> n){
		long long sum;
		if (n == 1)sum = 0;
		else {
			sum = 1;
			for (int i = 4; (i - 1) < n + 1; i += 4) {
				if (isprime(i - 1))sum++;
				if (isprime(i + 1))sum++;
			}
		}
		cout << sum << '\n';
	}
	return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;
 
 int kk[10*10];
 
 bool isPrime(int x)
 {
   for(int i=3;i<=(int)(sqrt(x));i=i+2) 
   {
     if(x%i==0) return false;        
   }    
   return true;
 }
 
 int main()
 {
   int n;
   while(cin>>n)
   {
      if(n==1) cout<<"0"<<endl;
      else if(n==2) cout<<"1"<<endl;
      else
      {
        int count=1;
        for(int i=3;i<=n;i++) if(isPrime(i)) count++;
        cout<<count<<endl;
      } 
   }
   //while(1);      
   return 0;    
 }

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

using namespace std;

bool isprime(int n) {
	if (n < 2)
		return false;
	int lim = (int)sqrt((double)n);
	for (int i = 2; i <= lim; i++)
		if (!(n%i))
			return false;
	return true;
}

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

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int keta(int x){
	int i=0;
	while (x/pow(10,i)>=1){
		i++;
	}
	if (x==0){
		return 1;
	}
	else
	return i;
	}


int main(){
int n;
while (cin>>n){
	int yakusu=0;
	for (int i=2;i<=n;i++){
		bool flag=true;
		for (int j=2;j<i-1;j++){
			if(i%j==0){
				flag=false;
			}
		}
		if (flag){
		yakusu++;
		}

	}
cout<<yakusu<<endl;
}
return 0;
}

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

constexpr int LIM = 1000000;

static char isprime[LIM];
static int numofprime[LIM];

void setprime(int N) {
    fill(isprime, isprime + N + 1, 1);
    isprime[0] = isprime[1] = 0;
    for(int x = 2, lim = (int)sqrt(N); x <= lim; ++x) {
        if(isprime[x]) {
            for(int y = x * x; y <= N; y += x) {
                isprime[y] = 0;
            }
        }
    }
    numofprime[0] = 0;
    for(int x = 0; x < N; ++x) {
        numofprime[x + 1] = numofprime[x] + isprime[x + 1];
    }
}

int main() {
    setprime(999999);
    int n;
    while(scanf("%d", &n) != EOF) {
        printf("%d\n", numofprime[n]);
    }
    return 0;
}

C++: #include<iostream>
#include<sstream>
#include<cstdio>
#include<fstream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;

bool is_prime(int n){
	if(n<=1)return false;
	if(n==2)return true;
	if(!(n&1))return false;
	for(int x=3;x<=sqrt(n);++x) if(!(n%x))return false;
	return true;
}

int main(){
	int n;
	while(scanf("%d",&n)==1){
		int tot = 0;
		if(n>=2)++tot;
		for(int x=3;x<=n;x+=2){
			if(is_prime(x))++tot;
		}
		cout<<tot<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int ans[1000000];

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

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

using namespace std;

#define MAX_N 999999
#define MAX_D 30

bool prime_check(int n, int k = 2)
{
	if (n < k * k) { return true; }

	if (n % k == 0) { return false; }

	return prime_check(n, k + 1);
}

int main()
{
	int n;

	bool isprime[MAX_N + 1];

	for (int i = 2; i < MAX_N + 1; i++)
	{
		isprime[i] = prime_check(i);
	}

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

		for (int i = 2; i <= n; i++)
		{
			if (isprime[i] == true)
			{
				c++;
			}
		}

		cout << c << endl;
	}

	return 0;
}

C++: #include<iostream>
 
using namespace std;
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
  return 0;
}

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

int main(void)
{
	const  int MAX = 1000000;
	int number =0;
	int count = 0;
	bool noPrim[MAX];
	int p_count=0;

	for(int i=0;i<MAX;i++){
		noPrim[i]=false;
	}
	int j;
	for(int i=2;i<MAX;i++){
		if(noPrim[i]==true)break;
		j=i*2;
		while(j<MAX){
			noPrim[j]=true;
			j+=i;
		}
	}
	while(cin >>  number){
		count = 0;
		for(int i=2;i<=number;i++){
			if(noPrim[i]==false)count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
const long long int N=1000000;
vector<int> prime;
bool arr[N];
void init(){
memset(arr,true,sizeof(arr));
arr[0]=arr[1]=false;
for(int i=2;i<N;++i){
    if(arr[i])
        prime.push_back(i);
    for(int j=0;j<prime.size()&&i*prime[j]<N;j++)
    {
        arr[i*prime[j]]=false;
        if(i%prime[j]==0)
            break;
    }
}
}
int main(){
int n;
init();
while(scanf("%d",&n)!=EOF){
    int j=0;
    for(;prime[j]<=n;j++);
    printf("%d\n",j);
}
}