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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

C++: #include <cstdio>
#include <cstring>
const int MAX_n = 999999;
bool isPrime[MAX_n+1];
int sum[MAX_n+1];
int main()
{
    memset(isPrime,true,sizeof(isPrime));
    for(int i = 2; 2*i <= MAX_n ; ++i)
        if(isPrime[i])
            for(int j = 2*i; j <= MAX_n; j+=i)
                isPrime[j] = false;
    isPrime[0] = isPrime[1] = false;
    
    for(int i = 0; i < MAX_n; ++i)
        sum[i+1] = sum[i] + isPrime[i+1];
    
    int n;
    while(scanf("%d",&n) != EOF)
    {
        int ans = sum[n];
        printf("%d\n",ans);
    }
    
}

C++: #include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=1000001;
bool p[MAXN];
vector<int> a;
int main(){
	memset(p,false,sizeof(p));
	for (int i=2;i<sqrt(MAXN);i++)
		for (int j=i+i;j<MAXN;j+=i)
			p[j]=true;
	for (int i=2;i<MAXN;i++)
		if (!p[i])
			a.push_back(i);
	int n;
	while (cin >> n){
		vector<int>::iterator f=lower_bound(a.begin(),a.end(),n);
		if (*f==n)
			cout << f-a.begin()+1 << endl;
		else
			cout << f-a.begin() << endl;
	}
	return 0;
}

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


using namespace std;

int main() {
	vector<int> prime_num{ 2, 3 };
	int n;

	while (cin >> n){
		int result;
		if (n <= 1) {
			result = 0;
		}
		else if (n == 2){
			result = 1;
		}
		else if (n < prime_num.back()){
			result = count_if(prime_num.begin(), prime_num.end(), [n](int a){return a <= n; });
		}
		else {
			for (int i = prime_num.back() + 2; i <= n; i += 2) {
				if (all_of(prime_num.begin(), prime_num.end(), [i](int a){return (i % a) != 0; })) {
					prime_num.push_back(i);
				}
			}
			result = prime_num.size();
		}


		cout << result << endl;javascript:void(0)
	}


	return 0;
}

C++: /*
 0…未確定
 1…素数
 2…素数でない
*/
#include <iostream>

using namespace std;

int main(){
    int num[1000000]={0}, b, a, n, c;
    for(int i=2;i<=1000;i++){
        if(num[i]==0){
            num[i]=1;
            b=1;
            while((a=(++b*i))<1000000) num[a]=2;
        }
    }
    
    while(cin >> n){
        c=0;
        for(int i=2;i<=n;i++) {
            if(num[i]==1) c++;
        }
        cout << c << endl;
    }
    return 0;
}

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

int CountPrime(int N);
int CheckPrime(int N);
bool IsPrime(int num);

int main()
{
	int N;

	while (std::cin >> N)
	{
		std::cout << CountPrime(N) << std::endl;
	}
}

int CountPrime(int N)
{
	int Counter = 0;

	for (int i = 1; i <= N; i++)
	{
		Counter += CheckPrime(i);
	}

	return Counter;
}

int CheckPrime(int N)
{
	if (IsPrime(N))
		return 1;

	return 0;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????

	double sqrtNum = std::sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int n;
    int p = 0;
    
    cin >> n;
    
    for(int x=n; x>=1; x--)
    {
            int c = 0;
            for(int y=1; y<=x; y++)
            {
                    if(x%y==0)
                    c++;
            }
            
            if(c==2)
            {
                    cout << x << endl;
                    p++;
            }
    }
    
    cout<< p << endl;
    

return 0;
}

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

int main() {
	int N;
	while (cin >> N) {
		vector<int> v(N + 1, 1);
		v.at(0) = 0;
		v.at(1) = 0;

		int r = sqrt(N);
		for (int i = 2; i <= r; i++) {
			int& p = v.at(i);
			if (p == 1) {
				for (int j = i*2; j <= N; j+=i) {
					int& p2 = v.at(j);
					if (!(j % i)) {
						p2 = 0;
					}
				}
			}
			else {
				continue;
			}
		}

		int c = count(v.begin(), v.end(), 1);
		cout << c << endl;
	}
}

C++: #include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

#define N 1000005

bool isPrime [N];

void seive()
{
    memset(isPrime, true, sizeof N);

    isPrime [0] = isPrime [1] = false;

    for ( int i = 4; i < N; i += 2 )
        isPrime [i] = false;

    int squareRoot = (int) sqrt (N);

    for ( int i = 3; i <= squareRoot; i += 2 ) {
        for ( int j = i * i; j < N; j += i )
            isPrime [j] = false;
    }
}

int main(int argc, const char * argv[])
{
    seive();

    int n;

    while ( scanf ("%d", &n) != EOF ) {
        int ans = 0;

        for ( int i = 2; i <= n; i++ ) {
            if (isPrime [i]) ans++;
        }

        printf ("%d\n", ans);
    }

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	int i = 2;
	while (i <= num) {
		if (i == 2) {
			count++;
			i++;
			continue;
		}
		else if (i % 2 == 0) {
			//count++;
			i++;
			continue;
		}
		else {
			// Route Num?????´??°??¨??????????????????
			int routeN_int = (int)sqrt(i);
			int j = 3;
			while (1) {
				if (j > routeN_int) {
					count++;
					break;
				}
				if (i % j == 0) {
					break;
				}
				j += 2;
			}
		}
		i++;
	}


	return count;
}

int main() {

	int num = 0;
	while (cin >> num) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}

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

int main(){
	int n;
	int *prime,i,j;
	prime = new int[80000];
	int *answer = new int[MAX];
	int count;
	bool flag;

	count = 0;
	answer[0] = 0;
	answer[1] = 0;
	answer[2] = 1;
	for(i = 3; i <= 1000000; i+=2){
		flag = true;
		for(j = 0; j < count; j++){
			if(i % prime[j] == 0){
				flag = false;
				break;
			}
			if(prime[j] * prime[j] > i) break;
		}
		if(flag == true){
			prime[count++] = i;
		}
		answer[i] = count + 1;
		answer[i+1] = count + 1;
	}
	while((cin >> n)!= NULL){
		cout << answer[n] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int num[1000000];
	for (int i = 0; i < 1000000; i++) {
		num[i] = 1;
	}
	num[0] = 0;
	num[1] = 0;

	for (int i = 2; i < 1000000; i++) {
		for (int j = 2; i * j < 1000000; j++) {
			num[i * j] = 0;
		}
	}

	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = n; i >= 2; i--) {
			if (num[i]) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}