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>
#include<string>
int main(){for(int m,n,o,c,d,e,i;!(std::cin>>n).eof();){if(n<3)e=n>1;else{bool*v=new bool[c=(n&1?n:--n)/2+1];memset(v,1,c);for(i=m=e=1;i<c;i++){for(m=i;m<c&&!v[m];)m++;if(m==c)break;e++;for(d=o=m*2+1;d<n+1;d+=o*2)v[d/2]=0;if(n<o*o)break;}for(i=1;i<c;)e+=v[i++];delete[]v;}printf("%d\n",e);}}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define Max 1000000
bool vis[Max];
int prime[Max],cnt;
void print_prime()
{
    memset (vis,false,sizeof (vis));
    for (int i=2;i<=sqrt(Max);i++)
        if (!vis[i])
        for (int j=i*i;j<=Max;j+=i)
        vis[j]=true;
    for (int i=2;i<=Max;i++)
        if (!vis[i])
        prime[cnt++]=i;
}
int main()
{
    print_prime();
    int n;
    while (scanf("%d",&n)!=EOF) {
        int i=0;
        while (prime[i]<=n) {
            i++;
        }
        printf("%d\n",i);
    }
    return 0;
}

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

int main() {
    const int MAX = 1000000;
    bool isPrime[MAX];
    fill_n(isPrime, MAX, true);
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = 2 * i; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    int n;
    while (cin >> n) {
        int count = 0;
        for (int i = 2; i <= n; i++) {
            count += isPrime[i];
        }
        cout << count << endl;
    }
}

C++: #include <stdio.h>
#include <string>
#include <iostream>

//using namespace std;

int sosuu(int n);

int main(){
    int n = 0;
    int temp = 0;
    while(scanf("%d",&n)!=EOF){
        if(n==1){
            printf("%d",0);
        }else{
            for(int i=2; i<=n; i++ ){
                temp+=sosuu(i);
            }
            printf("%d",temp);
        }
    }
    
    
}

int sosuu(int n){
    for(int i=2; i<n; i++){
        if(n%i == 0){
            return 0;
        }
    }
    return 1;
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

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

#define MAX 999999

using namespace std;

int num_prime[MAX];
bool not_prime_flag[MAX];

int main()
{
    int n;
    int max_input;
    vector<int> input;

    while (cin>>n){
        input.push_back(n);
    }
    max_input=*max_element(input.begin(),input.end());
    for (int i = 1; i < max_input; ++i) {
        if(!not_prime_flag[i]){
            for (int j = 2; (i+1)*j-1 < max_input; ++j) {
                not_prime_flag[(i+1)*j-1] = true;
            }
        }
        num_prime[i]=num_prime[i-1]+!not_prime_flag[i];
    }
    for (int i:input) {
        cout<<num_prime[i-1]<<endl;
    }
    return 0;
}

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

int main(void)
{
	int prime[168] = {0};
	unsigned long n;
	prime[0] = 2, prime[1] = 3;

	for(int i = 5; i < 1000; i += 2) {
		bool p_flag = true;
		int j;
		for(j = 0; prime[j] != 0; j++) {
			if(i % prime[j] == 0) {
				p_flag = false;
				break;
			}
		}
		if(p_flag == true) {
			prime[j] = i;
		}
	}

	while(cin >> n){
		unsigned long cnt = 2;

		if(n == 1) {
			cout << 0 << endl;
			continue;
		} else if(n == 2) {
			cout << 1 << endl;
			continue;
		} else if(n == 3 || n == 4) {
			cout << 2 << endl;
			continue;
		}

		for(unsigned long i = 5; i <= n; i += 2) {
			bool p_flag = true;
			for(int j = 1; prime[j] <= (int)sqrt((double)i) + 1; j++) {
				if(i % prime[j] == 0) {
					p_flag = false;
					break;
				}
			}
			if(p_flag == true) {
				cnt++;
			}
		}

		cout << cnt << endl;
	}
	
	return 0;
}

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

int main(){
    int n;
    const int N = 1e6;

    vector<bool> is_prime(N,true);
    is_prime[0] = false;
    is_prime[1] = false;

    for(int i=2;i*i<N;i++){
        if(is_prime[i]){
            for(int j=i*2;j<N;j+=i){
                is_prime[j] = false;
            }
        }
    }

    vector<int> cnt_prime(N,0);
    for(int i=1;i<N;i++){
        if(is_prime[i]) cnt_prime[i]++;
        cnt_prime[i] += cnt_prime[i-1];
    }

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

}

C++: #include <iostream>

#define N 1000000

using namespace std;

int main() {
	int n;
	bool p[N];
	for(int i = 0; i <= N; i++) p[i] = 0;
	for(int i = 3; i <= N; i += 2) p[i] = 1;
	p[2] = 1;
	for(int i = 0; i < N; i++){
		if(!p[i]) continue;
		for(int j = 2 * i; j < N; j += i) p[j] = 0;
	}

	while(cin >> n){
		int j = 0;
		for(int i = 0; i <= n; i++){
			if(p[i]) j++;
		}
		cout << j << 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)/2;
		for(i=3;i<=n;i+=2){
			sqrtn=(int)sqrt(i);
			for(j=1;j*5-1<sqrtn;j++){
				if(i%(j*5+1)==0 || i%(j*5-1)==0){
					sum--;
					break;
				}
			}
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

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

using namespace std;

int main(){
  int k, n;
  vector<int> prime;
  vector<int>::iterator i, j;

  cin >> n;

  for(k=2; k<=n; ++k)
    prime.push_back(k);

  i = prime.begin();
  while(i != prime.end()){
    j = i + 1;
    while(j != prime.end()){
      if((*j)%(*i) == 0)
        j = prime.erase(j);
      else
        ++j;
    }
    ++i;
  }

  cout << prime.size() << endl;
  return 0;
}

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

int PrimeCount(int n){
	int A[n+5];
	memset(A,0,sizeof(A));//0は素数
	for(int i=2;i*i<=n;i++){
		if(A[i]==0){
			for(int j=i*2;j<=n;j+=i){
				A[j]=1;
			}
		}
	}
	int count=0;
	for(int i=2;i<=n;i++){
		if(A[i]==0) count++;
	}
	return count;
}

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

C++: 
int main()
{
    bool num[1000000]={false};
    for(int i=2;i<1000;i++){
        if(!num[i]){
            for(int j=i*i;j<1000000;j+=i){
                num[j]=true;
            }
        }
    }
    int n;
    while(cin>>n){
        int ans=0;
        for(int i=2;i<=n;i++){
            if(!num[i])
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		if ( n <= 1 )
			cout << "0" << endl;
		
		vector <bool> p(n+1, true);

		p[0] = p[1] = false;
		for ( int i = 4; i <= n; i += 2 )
		{
			p[i] = false;
		}

		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
			{
				for ( int j = i+i; j <= n; j += i )
				{
					p[j] = false;
				}
			}
		}

		int kotae = 1;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
				kotae++;
		}

		cout << kotae << endl;
	}

	return 0;
}