Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  int n;
  while(cin>>n){
    int res=0;
    bool notPrime[n+1];
    memset(notPrime,0,sizeof(notPrime));
    
    notPrime[0] = notPrime[1] = true;

    for(int i=2; i<=n; i++){
      if(!notPrime[i]){
	res++;
	for(int j=2*i; j<=n; j+=i){
	  notPrime[j] = true;
	}
      }
    }
    cout << res << endl;
  }


  return 0;
}

C++: #include <iostream>

using namespace std;

#define MAX 1000000

int main(){
  int n;
  bool p[MAX];
  p[0] = p[1] = false;
  for(int i=2;i<MAX;i++)p[i] = true;
  for(int i=2; i<MAX;i++){
	if(p[i]){
	  for(int j=i+i;j<MAX;j=j+i){
		p[j] = false;
	  }
	}
  }
  
  while(cin >> n){
	int cnt = 0;
	for(int i = 0;i<=n;i++){
	  if(p[i]) cnt++;
	}
	cout << cnt << endl;
  }
  
  return 0;
}

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

int main(){
	const int max_num=1000000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={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 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
        int n;

        while (cin >> n) {
                bool *isPrime = new bool[n + 1];
                isPrime[0] = false;
                isPrime[1] = false;
                for (int i = 2; i < n + 1; i++) {
                        isPrime[i] = true;
                }
                for (int i = 2; i <= (int)sqrt(n); i++) {
                        if (isPrime[i]) {
                                for (int j = i + 1; j <= n; j++) {
                                        if (isPrime[j]) {
                                                if (!(j % i)) {
                                                        isPrime[j] = false;
                                                }
                                        }
                                }
                        }
                }
                int ans = 0;
                for (int i = 2; i <= n; i++) {
                        if (isPrime[i]) {
                                ans++;
                        }
                }
                cout << ans << endl;
                delete [] isPrime;
        }

        return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#define mem(name,value) memset(name,value,sizeof(name))
#define loop(i,from,to) for(int i=from;i<to;i++)
#define loopr(i,from,to) for(int i=from;i>=to;i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=0x3f3f3f3f;

const int maxn=1000000+5;
int pr[maxn];
bool is_pr[maxn];

int sieve(int n){
    int p=0;
    loop(i,0,n+1) is_pr[i]=true;
    is_pr[0]=is_pr[1]=false;
    loop(i,2,n+1){
        if(is_pr[i]){
            pr[p++]=i;
            for(int j=2*i;j<=n;j+=i)
                is_pr[j]=false;
        }
    }
    return p;
}

int main()
{
    int n;
    while(cin>>n)
        cout<<sieve(n)<<endl;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n, cnt;	
	bool prime[1000000];
	while(cin >> n){
		prime[n] = {false};
		prime[1] = true;
		
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] = true;
				}
			}
		}
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

C++: #include <iostream>
using namespace std;
bool isPrime(int n) {
    bool flag = false;
    if(n % 2 == 0) {
        if(n==2){
            flag=true;
        }
    }
    else {
        for(int i=2;i<n;i++) {
            if(n==i)break;
            else if(n % i==0){
                flag=false;break;
            }else flag=true;
        }
    }
    return flag;
}
int main(void){
    int n=0;
    int count = 0;
    while(cin>>n) {
        count = 0;
        for(int i=2;i<=n;i++) {
            if(isPrime(i))count++;
        }
        std::cout << count << std::endl;
    }
}

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	for(int a = 3;a<1000000;a++)
	{
		prime[a] = 1;
	}
	
	for(int a = 3;a<1000;a++)
	{
		if(checked[a] == 0)
		{
			checked[a] = 1;
			for(int b = 2;b<a;b++)
			{
				if(a%b==0)
				{
					prime[a] = 0;
					break;
				}
			}
			if(prime[a] == 1)
			{
				for(int c = 2*a ;c<1000000;c+=a)
				{
					checked[c] = 1;
					prime[c] = 0;
				}
			}
		}
	}

	for(int a = 3;a<100;a++)
	{
		primesum[a] = primesum[a-1]+=prime[a];
	}
	
	while(cin >> n)
	{
		cout << primesum[n] << endl;
	}

	return 0;
}

C++: 
#include <iostream>

using namespace std;

int main()
{
	int n, count,k;

	while(cin >> n){
		count = 1;
		k = 0;

		for(int i = 3; i <= n; i += 2){
			for(int j = 3; j <= std::sqrt((double)i); j += 2)
			{
				if(i%j == 0){
					k = 1;
					break;
				}
			}
			if(k == 0){
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
	int n;

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

		for(int i = 2; i <= n; i++) {
			int yaku = 0;
			for(int j = 1; j <= i; j++) {
				if(i % j == 0) {
					yaku++;
				}
			}
			if(yaku == 2) {
				count++;
			}
		}

		cout << count << endl;
	}
}