Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

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

int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		int count=0;
		std::vector<int> num;
		int max=2;
		for(int m=2;m<=n;m++){
			bool check=true;
			for(int i=0;i<count;i++){
				if(m!=num[i] && m%num[i]==0){
					check=false;
					if(max<m){
						max=m;
					}
					break;
				}
			}
			if(check==true){
				if(count>0){
					if(max>num[count-1]){
						for(int i=max+1;i<m;i++){
							if(i!=m && m%i==0){
								check=false;
								if(max<m){
									max=m;
								}
								break;
							}
						}
					}
					else{
						for(int i=num[count-1]+1;i<m;i++){
							if(i!=m && m%i==0){
								check=false;
								if(max<m){
									max=m;
								}
								break;
							}
						}
					}
				}
				else{
					for(int i=max;i<m;i++){
						if(i!=m && m%i==0){
							check=false;
							if(max<m){
								max=m;
							}
							break;
						}
					}
				}
			}
			if(check==true){
				num.push_back(m);
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n,i,j;
	cin>>a;
	n=0;
	for(i=2;i<=a;i++){
		for(j=2;j<i;j++){
			if(i%j==0)break;
		}
		if(i == j) n += 1;
	}
	cout<<n;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    vector<int> nl;
    int mx = 0;
    do{
        int n;
        cin >> n;
        if (!cin.eof()){
            nl.push_back(n);
            mx = max(mx, n);
        }else{
            break;
        }
    }while(1);


    double r = sqrt(mx);

    list<int> sl;
    vector<int> primes;

    for (int i = 2; i <= mx; i++) {
        sl.push_back(i);
    }

    while (sl.front() <= r) {
        int p = sl.front();
        primes.push_back(p);
        sl.pop_front();

        auto i = sl.begin();
        while(i != sl.end()){
            if(*i % p == 0){
                i = sl.erase(i);
            }
            else {
                i++;
            }
        }
    }

    for (auto&& i : sl) {
        primes.push_back(i);
    }

    for (auto&& n : nl) {
        auto p = upper_bound(primes.begin(), primes.end(), n);
        cout << p - primes.begin() << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,k,kk;
	while(cin>>n){
		kk=0;
		for(int j=3;j<=n;j+=2){
			k=0;
			for(int i=3;i<=sqrt(j);i+=2){
				if(j%i==0)k++;
		        }
		     if(k==1)kk++;
		   }
		if(n==1)cout<<"0"<<endl;
		else if(n==2)cout<<"1"<<endl;
		else cout<<kk+1<<endl;
	   }
	return 0;
	}

C++: #include<iostream>
#define N 999999
int p[(N+1)/2];int m[N+1];void k();using namespace std;main(){int n;p[0]=2;m[1]=0;m[2]=1;k();while(cin>>n){cout<<m[n]<<endl;}}void k(){int i,j,e=1;for(i=3;i<N+1;i++){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;tag:m[i]=e;}}

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

using namespace std;

int pri[1000000];

int main()
{

    pri[0]=1;
    pri[1]=1;

    for(int i=4;i<1000000;i+=2)
    {
        pri[i]=1;
    }

    for(int i=2;i*i<1000000;i++)
    {
        for(int j=2;j*i<1000000;j++)
        {
            pri[i*j]=1;
        }
    }
    int n,c;
    while(scanf("%d",&n))
    {
        c=0;
        for(int i=2;i<=n;i++)
        {
            if(pri[i]==0)
            {
                c++;
            }
        }
       printf("%d\n",c);

    }

    return 0;
}

C++: //--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

bool is_prime(int a) {
	int now = 2;
	while (now*now <= a) {
		if (a%now == 0)return 0;
		else now++;
	}
	return 1;
}


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

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

int primes[78498], num_primes = 1;
int calculated = 2;
int count_pos(int n) {
	for (int i = 0; i < num_primes; i++) {
		if (primes[i] == n) {
			return i + 1;
		}
		else if (primes[i] > n) {
			return i;
		}
	}
	return num_primes;
}
int main() {
	primes[0] = 2;
	while (true) {
		int n;
		if (!scanf_s("%d", &n)) break;
		if (calculated+1 < n) {
			for (int i = calculated + 1; i < n + 1; i += 2) {
				bool is_prime = true;
				for (int w = 3; w < (int)(sqrt(i)) + 1; w += 2) {
					if (i%w == 0) {
						is_prime = false;
						break;
					}
				}
				if (is_prime) {
					primes[num_primes++] = i;
				}
			}
			calculated = n - (n % 2);
		}
		printf("%d\n", count_pos(n));
	}
}

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>

int main() {
	int input;
	std::cin >> input;

	int count = 0; // input??\???????????¶??°????????¨???????´???°???????¨?
	for (; input > 1; input--) {// input???1???????????????????????????????????¨???????????????
		/*
		 * 5
		 * 4
		 * 3
		 * 2
		 */
		bool fl = true;
		for (int i = 2; i < input; i++) // 1 < i < input ????????¶??????????????°????????§?????????
			/*
			 * 5 -> 2, 3, 4
			 * 4 -> 2, 3
			 * 3 -> 2
			 * 2 ->
			 */
			 // ?????????????????°????????¨??????????????????????????????
			if (!(input % i))
				fl = false;

		if (fl)
			count++;
	}

			std::cout << count << std::endl;
}