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<iostream>
using namespace std;
 
static const int MAX = 1000000;

int main() {
    static bool is_prime[MAX] = { false };
    static int npr[MAX];
    for (int i = 2; i<MAX; i++) {
        if (!is_prime[i]) {
            for (int j = 2; j*i<MAX; j++) {
                is_prime[i*j] = true;
            }
        }
        npr[i] = npr[i - 1] + !is_prime[i];
    }
    int n;
    while (cin >> n) {
        cout << npr[n] << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
using namespace std;
int prime[1000005];
bool is_prime[1000005];
int seve(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=2*i;j<=n;j+=i)
                is_prime[j]=false;
        }
    }
    return p;
}
int main(void)
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",seve(n));
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    vector<bool> prime(1000000,true);
    prime[0]=false;
    prime[1]=false;
    for(int i=2;i<1000000;i++){
        if(prime[i]==false)continue;
        for(int j=2*i;j<1000000;j+=i){
            prime[j]=false;
        }
    }
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for(int i=2;i<=n;i++){
            if(prime[i])ans++;
        }
        out(ans);
    }
}

C++: #include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
#define MAX_N 1000001

int main(){
	int *count;
	count=(int *)malloc(sizeof(int)*MAX_N);
	int cnt=0;
	bool *a;
	a= (bool *)malloc(sizeof(bool)*MAX_N);
	a[1]=true;

	for(int i=2;i<MAX_N;i++){
		count[i]=cnt;
		if(a[i])continue;
		cnt++;
		count[i]++;
		//int k=1;
		long int k=i;//i??\???????????????????????????
		while(i*k<MAX_N){
			a[i*k]=true;
			k++;
		}

	}

	int n;
	while(cin >> n){
		cout << count[n] << endl;
	}
	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) {
	// num???????´???°?????°
	int count = 0;

	// Route Num?????´??°??¨??????????????????
	int routeN_int = (int)sqrt(num);
	//cout << routeN_int << endl;

	// ???n?????§?????´??°?????????????´???°????????°????????????
	//vector<bool> prime_flag_set(num + 1, true);
	vector<int> prime_flag_set(num + 1, 1);
	
	/*
	for (int i = 0; i < prime_flag_set.size(); i++) {
		prime_flag_set[i] = true;
	}
	*/
	
	//cout << endl;
	// 1???2 ?????? n ?????§?????´??°????????????p????????°????????? = false
	for (int p = 2; p < prime_flag_set.size(); p++) {
		if (prime_flag_set[p] == 0) {
			continue;
		}
		int j = 2;
		// 3???2??????????????°?????????????????????p ??? ???n ????¶????????????????
		while (p <= routeN_int) {
			if (p*j > num) {
				// num??\???
				break;
			}
			prime_flag_set[p * j] = 0;
			//p????????°????±???????
			j++;
		}
	}
	// 2??\???
	for (int i = 2; i < prime_flag_set.size(); i++) {
		if (prime_flag_set[i] == 1) {
			count++;
		};
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}

	return count;
}

int main() {

	int num = 0;
	while (cin >> num, num != 0) {
		//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>
using namespace std;

int is_it_primeNum(int n)
{
	int a = 1;
	if (n == 0 || n == 1)
		return 0;
	else if (n == 2)
		return 1;
	else if(n % 2 == 0)
		return 0;
	else{ 
		for(int i=3;i<n/2;i+=2){
			if (n%i==0){
				a = 0;
				break;}
		}
	}
	return a;
}
int how_much_primeNum(int n)
{
	int ans = 0;
	for(int i=2;i<=n;i++){
		ans += is_it_primeNum(i);
	}
	return ans;
}

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

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

int main(){
	int  n,i,j,sqrtn,sum;
	while(scanf("%d",&n)!=EOF){
		sum=n-1;
		for(i=2;i<=n;i++){
			sqrtn=(int)sqrt(i);
			for(j=2;j<sqrtn;j++){
				if(i%j==0){
					sum--;
					break;
				}
			}
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

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


int main() {

//変数の宣言

	vector<int> prime;
	int i,n,j;
	
	while(cin >> n){
		prime.push_back(2);
		
		for(i=3;i<n+1;i++){
			for(j=0;j<prime.size();j++){
				if (i%prime[j]==0) break;
				if (j==prime.size()-1) {
					prime.push_back(i);
				}
			}
		}
		
		/*
		for(i=0;i<prime.size();i++){
			cout << prime[i] <<endl;
		}
		*/
		cout << prime.size() <<endl;
	}

	return 0;
}