Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: 

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

//Nayeem Shahriar Joy ,Applied Physics And Electronic Engineering , University of Rajshahi.


int main(){

    bool prime[1000002];

    memset(prime,true,sizeof(prime));

    prime[0]=false;

    prime[1]=false;

    for(int i=2;i*i<=999999;i++)
    {
        if(prime[i]==true)
        {
            for(int j=i*2;j<=999999;j=j+i)
            {
                prime[j]=false;
            }
        }
    }

 int n;

 while(cin>>n)

 {
     int count=0;

     for(int i=0;i<=n;i++)

     {
         if(prime[i]==true)
         {
             count++;
         }
     }
     cout<<count<<endl;
 }

    return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
#define MAX_SIZE 1000100
#define N 999999
int preme[MAX_SIZE];


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

int main(int argc, char *argv[]) {
	memset(preme, 0, sizeof(preme));
	int index = 0;
	for(int i = 1; i <= N; i += 2)
		preme[i] = 1;
	
	for(int i = 3; i <= 999999; i += 2) {
		if(preme[i]) {
			for(int j = i + i; j <= 999999; j += i)
				preme[j] = 0;
		}
			
	}
	
	int n;
	while(cin >> n) {
		int count = 0;
		for(int i = 1; i <= n; i++)
			if(preme[i])
				count++;
		cout << count << endl;
	}
		
}

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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) REP (i, 0, n)
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

const int MAX_N = 1000000;
bool prime[MAX_N];
void eratos() {
	rep(i, MAX_N) prime[i] = true;
	prime[0] = false;
	prime[1] = false;
	REP(i, 2, sqrt(MAX_N)) {
		if (prime[i]) {
			for (int j = 0; i * (j + 2) < MAX_N; ++j) {
				prime[i * (j + 2)] = false;
			}
		}
	}
}

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

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

bool isprime(int x) {
	if (x == 2)
		return true;
	if ((x < 2) || (x % 2 == 0)) {
		return false;
	}
	int i = 3;
	while (i == sqrt(x)) {
		if (x%i == 0)
			return false;
		i = i + 2;
	}
	return true;
}

int main()
{
	
	int n;
	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<stdio.h>

int s[100000] = {0};

int main(){
	int a,b,c,d,e;
	int temp;
	int cont = 0;
	
	while(scanf("%d",&a) != EOF){
		/*
		for(int i = 0; i < a; i++){
			s[i] = 1;
		}
		*/
		
		cont = 0;
		
		s[0] = 1;
		s[1] = 1;
		
		for(temp = 2; temp < a; temp++){
			if(s[temp] == 0){
				for(b=temp; b < a; b+= temp){
					if(b == temp){
						s[b] = 0;
					}
					else{
						s[b] = 1;
					}
				}
			}
		}
		
		for(c = 0; c < a; c++){
			if(s[c] == 0){
				
	//		printf("%d\n",c);
				cont++;
			}
		}
		
		printf("%d\n",cont);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  bitset<1'000'000> bs;
  bs.set();
  bs[0] = bs[1] = false;
  for (int p = 2; p <= 1000; ++p) {
    for (int i = p * p; i < 1'000'000; i += p) bs[i] = false;
  }
  string s;
  while (getline(cin, s)) {
    int n = stoi(s);
    int res = 0;
    for (int i = 0; i <= n; ++i) res += bs[i];
    cout << res << '\n';
  }
}

C++: #include <cstdio>
#define max_n 999999
int prime[max_n];
bool is_prime[max_n+1];
int main(){
    for(int i=0; i<max_n; i++){
        is_prime[i]=true;
    }
    int p = 0;
    is_prime[1]=false;
    is_prime[0]=false;
    for(int i=2;i<max_n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i;j<max_n;j+=i)is_prime[j]=false;
        }
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",n);
        int ans = 0;
        for(int i =0; i<max_n; i++){
            ans = 0;
            if(prime[i]>n){
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

using namespace std;

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

int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			bool check = isPrime(i);
			if (check) ans++;
		}
		cout << ans << endl;
	}
}

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

int Eratosthenes(int N){

  int count=0;
  bool* IsPrime = new bool[N];
  IsPrime[0] = false;
  IsPrime[1] = false;
  for(int i=2; i<=N;i++){
    IsPrime[i] = true;
  }
  for(int i=2; i*i<=N;i++){
    if(IsPrime[i]){
      for(int j=2*i; j<=N; j+=i)
        IsPrime[j] = false;
      }
  }
  for(int i=0; i<=N;i++)
    if(IsPrime[i]) count++;

  delete[] IsPrime;
  return count;
}

int main(void)
{
    int N[30]={};
    int count=0;
    int i=0;
    while(1){
      if(scanf("%d",&N[i])!=1)
        break;
      i++;
    }
    i=0;
    while(N[i]>0){
      count=Eratosthenes(N[i]);
      printf("%d\n",count);
      i++;
    }

    return 0;
}

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

bool Prime(int n);

int main(){

  int n;
  int sum;

  while(scanf("%d",&n)!=EOF){
    sum = 0;
    for(int i=3; i<=n; i+=2){
      sum += Prime(i);
    } 
    cout << sum+1 << endl;
  }

  return 0;
}


bool Prime(int n){

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

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

  return true;
}

C++: #include<stdio.h>
#include<math.h>
int gurobal[1000001]={0};
int main(void)
{
	int n=0;
	int i=0,j=0;
	int heihoukon=0;
	int count=0;
	while(scanf("%d",&n)!=EOF)
	{
		count=0;
		gurobal[1]=0;
		for (i=2;i<=n;i++)
		{
			gurobal[i]=1;
		}
		(int)heihoukon=sqrt((double)n);
		for (i=2;i<=heihoukon;i++)
		{
			if (gurobal[i]!=0)
			{
				for (j=i*2;j<=n;j+=i)
				{
					gurobal[j]=0;
				}
			}
		}
		for (i=2;i<=n;i++)
		{
			if (gurobal[i]!=0)
			{
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  bool num[1000000] = {false};
  for(int i=2; i<1000; i++){
    if(!num[i]){
      for(int j = i*i; j<1000000; j+=i){
    num[j] = true;
      }
    }
  }
  int n;
  while(cin >>n){
    int ans = 0;
    for(int i=2; i<=n; i++){
      if(!num[i]){ans++;}
    }
    cout <<ans<<endl;
  }
  return 0;
}