Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int eratosthenes(int n, vector<bool>& prime) {
    int ret = 0; prime.assign(n, false);
    vector<bool> chk(n, false);
    for (auto i = 2; i < n; i++) {
        if(chk[i]) continue;
        ret++; prime[i] = true;
        for (auto j = i; j < n; j += i) chk[j] = true;
    }
    return ret;
}

int main(){
    vector<bool> prime; eratosthenes(1000000, prime);
    vector<int> cnt(1000000, 0);
    for (auto i = 0; i < 1000000; i++) {
        if(prime[i]) cnt[i]++;
        cnt[i + 1] += cnt[i];
    }

    string s;
    while(cin >> s){
        int n = stoi(s);
        cout << cnt[n] << endl;
    }
    return 0;
}

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

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
#include <cctype>
#include<queue>
#include<stack>
#include<cstdio>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int ans=n-1;
		int d[999999+100]={};
		for(int i=2;i<=n;i++){
			for(int j=3;j<=n;j++){
				if(d[j]==0 && j%i==0 && j!=i){
					d[j]=1;
					ans--;
				}
			}
		}
		cout<<ans<<endl;
	}
		return 0;
}

C++: #include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

bool prime[1000000];
li sum[1000000];

int main(){
	rep(i,1e+6)prime[i]=true;
	prime[0]=prime[1]=false;
	
	repp(i,2,sqrt(1e+6)+1){
		for(li j=2; j*i<=1e+6; j++){
			prime[i*j]=false;
		}
	}
	
	sum[0]=0;
	repp(i,1,1e+6)sum[i]=sum[i-1]+(prime[i]?1:0);
	
	li n;
	while(cin>>n){
		cout<<sum[n]<<endl;
	}
	
	return 0;
}

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

bool is_prime(int n,int r);

int main(void) {
	using namespace std;
	int x;
	int count;

	while (cin >> x) {
		count = 0;
		double r = pow(x, 0.5);
		for (int i = 2; i <= x; i++) {
			if (is_prime(i,r))count++;
		}
		cout << count << endl;
	}
	return 0;
}



bool is_prime(int n,int r) {
	static int flag = 0;
	static int list[78498];
	static int count = 0;
	if (flag == 1) {
		for (int i = 0; i < count; i++) { 
			if (list[i] >r) {
				return true;
			}
			if (n % list[i] == 0) {
				if (n == list[i]) {
					
					return true;
				}
				
				return false;
			}
		}

	}
	flag = 1;
	list[count] = n;		
	count++;
	
	return true;
}

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

using namespace std;

int prime[100000];
bool is_prime[1000000];

int sosuu(int n){
    int p=0;
    for (int i=0; i<=n; i++)
        is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for (int i=2; i<=n; i++) {
        if(is_prime[i]){
            prime[p++]=i;
            for (int j=i*2; j<=n; j+=i) {
                is_prime[j]=false;
            }
        }
    }
    return p;
}

int main(void){
    int n;
    while(cin>>n)
    cout<<sosuu(n)<<endl;
    return 0;
}

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

using namespace std;

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

	return true;
}

int main()
{
	// --- variable define --- //

	int n, c;


	// --- prime check ( 2 to 999999 ) --- //

	bool isprime[1000000];

	for (int i = 1; i < 1000000; i++)
	{
		if (prime_check(i) == true)
		{
			isprime[i] = true;
		}
		else
		{
			isprime[i] = false;
		}
	}


	// --- main --- //

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

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

		cout << c << endl;
	}
}

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

int prime[1000000];


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


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
  ;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j ++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

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

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

int main()
{
	int n, i,j,k,cnt;
	while (scanf("%d", &n) != EOF)
	{
		cnt = 0;
		if (n <= 1)
		{
			printf("0\n");
			continue;
		}
		if (n == 2)
		{
			printf("1\n");
			continue;
		}
		if (n <= 4)
		{
			printf("2\n");
			continue;
		}
		for (j = 5; j <= n; j+=2)
		{
			k = 0;
			for (i = 3; i <= sqrt(j*1.0); i += 2)
			{
				if (j%i == 0)
				{
					k = -1;
					break;
				}
			}
			if (k == -1)continue;
			cnt++;
		}
		printf("%d\n", cnt + 2);
	}
}

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

using namespace std;

    int g(int n){
        int p = 0;
        bool is_prime[n + 1];
        is_prime[0] = is_prime[1] = false;

        for(int i = 2 ; i <= n ; i++)
            is_prime[i] = true;

        for(int i = 2 ; i <= n ; i++){
            if(is_prime[i]){
                p++;
                for(int j = i * 2 ; j <= n ; j += i) // j = i * 2 like 2 started form 4 then add 2 each time j += i not j * 2
                    is_prime[j] = false;
            }
        }
    return p;
}

int main(){
    int n;

    while(cin >> n){
        cout << g(n) << endl;
    }

}

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

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

int main(){
	int n;
	while(cin >> n && n<1000000) {
		int s = 0;
			for (int j = 2;j <= n;j++){
				int yaku = 0;
				for (int m = 1;m <= j;m++){
					if (j % m == 0) yaku++;
				}
				if (yaku == 2) s++;
			}
			cout << s << endl;
	}
    return 0;
}