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 <math.h>
using namespace std;

int main(){
  
  int n;

  while(cin >> n){
    bool Prime[1000000] = {};
    int i,j,count;
    count = n;
    for(i = 2; i <= sqrt(n) ; i++){
      if(Prime[i] == false){        
	for(j = 2; i*j <= n ; j++){
	  if(!Prime[i*j]){
	    Prime[i*j] = true;
	    count--;
	  }
	}
      }
    }
    cout << count-1 << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int prime[1000000];
int main(){
    prime[0]=-1;
    prime[1]=-1;
    for(int i=2;i<1000000;i++){
        if(prime[i]==0){
            prime[i]=1;
            for(int j=i*2;j<1000000;j+=i)prime[j]=-1;
        }
    }
    int now;
    while(~scanf("%d",&now)){
        int ans=0;
        for(int i=1;i<now+1;i++)if(prime[i]==1)ans++;
        printf("%d\n",ans);
    }
}

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

int main()
{
	int a = 0, n;

	for (int j = 1; j <= 30; j++) {
		cin >> n;
		for (int i = 2; i <= n; i++) {
			if (i == 2) {
				a++;
			}
			else if (i == 3) {
				a++;
			}
			else if (i % 2 != 0 && i % 3 != 0) {
				a++;
			}
		}
		cout << a << endl;
		a = 0;
	}
	return 0;
}

C++: #include<stdio.h>
int main(){
	int a,b,c,n;
	c=0;
	scanf("%d",&n);
		for(a=2;a<=n;a++){
			for(b=2;b<=n;b++){
				if(a%b==0&&a!=b){
					break;
				}else if(a%b==0&&a==b){
					c++;
				}else{
				}
			}
		}
		printf("%d\n",c);
	return 0;
}

C++: #include <iostream>
#include <set>
using namespace std;
int main() {
  long n;
  set<long> primes;
  primes.insert(2);
  while (cin >> n) {
    for (int i = 3; i <= n; i++) {
      bool prime = true;
      for (long j : primes)
        if (i % j == 0) {
          prime = false;
          break;
        }
      if (prime) primes.insert(i);
    }
    int x = 0;
    for (long j : primes)
      if (j <= n) x++;
    cout << x << endl;
  }
}

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

int n;
int known_primes[500000];
int pointer = 0;

void dump_known_primes()
{
	for (int i = 0; i < pointer; i++) {
		std::cout << known_primes[i] << ' ';
	}
	std::cout << std::endl;
}

bool get_input()
{
//	std::cout << "get_input\n";
	return (std::cin >> n);
}

// a < known_primes[pointer+1] ÌÍÍÅ
// a ªf©Ç¤©»è·é
bool is_prime(int a)
{
//	std::cout << "is_prime\n";
	for (int i = 0; known_primes[i] <= std::sqrt(a); i++) {
		if (a % known_primes[i] == 0) {
			return false;
		}
	}
	return true;
}

// mçêÄ¢È¢ÌfðT·
void search_next_prime()
{
//	std::cout << "searcn_next_prime\n";
	int a;
	for (a = known_primes[pointer] + 2; !is_prime(a); a += 2);
	pointer++;
	known_primes[pointer] = a;
}

// XXX
int solve(int a)
{
//	std::cout << "solve\n";
	if (a <= known_primes[pointer]) {
//		std::cout << "a: " << a << ' ' << "pointer: " << pointer << std::endl;
		int i = pointer;
		while (a < known_primes[i]) {
//			std::cout << "i: " << i << std::endl;
			i--;
		}
		return i+1;
	} else {
		search_next_prime();
		return solve(a);
	}
}

int main()
{
//	std::cout << "main\n";
	known_primes[0] = 2;
	known_primes[1] = 3;
	known_primes[2] = 5;
	pointer = 2;
	while (get_input()) {
		std::cout << solve(n) << std::endl;
//		dump_known_primes();
	}
	return 0;
}

C++: #include<iostream>

int main(){

	bool data[100001];

	for (int i = 0; i < 100001; i++)
		if (i % 2 == 0)
			data[i] = false;
		else
			data[i] = true;

	int in;

	int res=0;

	for(int i=2;i<=100000;i++){
		if (i % 2 != 0) {
			for (int j = 2; j < i; j++) {
				if (i%j == 0) {
					data[i] = false;
					goto fl;
				}
			}
		}
	fl:;
	}

	while (true) {

		std::cin >> in;

		for (int i = 2; i <= in; i++) {
			if (data[i] == true)
				res++;
		}

		std::cout << res << std::endl;

	}

		return 0;
}

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

int getPrimeCount(int n) {
    vector<bool> isPrime(n+1, true);
    int count = 0;
    for (int i = 2; i <= n; i++) {
        if (isPrime[i]) {
            count++;
            for (int j = i*2; j <= n; j+=i) {
                isPrime[j] = false;
            }
        }
    }
    return count;
}

int main() {
    int n;
    while (cin >> n) {
        cout << getPrimeCount(n) << endl;
    }
}

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

const bool isPrime(const int p)
{
    if(p == 2)
    {
        return true;
    }

    if(p < 2 || p % 2 == 0)
    {
        return false;
    }

    for(int i = 3; i <= sqrt(p); i += 2)
    {
        if(p % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main(void)
{
    bool p[1000000];

    for(int i = 0; i < 1000000; ++i)
    {
        p[i] = isPrime(i);
    }

    int n;

    while(std::cin >> n)
    {
        int result = 0;

        for(int i = 0; i <= n; ++i)
        {
            result += p[i];
        }

        std::cout << result << std::endl;
    }

    return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	unsigned long long int i;
	int n, p, cnt,fg;
	while (cin >> n) {
		cnt = 0;
		fg = 0;
		for (i = 3; i <= n; i+=2) {
			for (int j = 3; j <= (int)sqrt(i); j += 2) {
				if (i%j == 0) {
					fg = 1;
					break;
				}
			}
			if (fg)
				fg = 0;
			else
				cnt++;
		}
		//printf("cnt=%d\n", cnt);
		if (n >= 2)
			cnt++;
		cout << cnt << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<cstring>
int main(){
 int n,cnt=0;
 scanf("%d",&n);
 int a[n+1];
 memset(a,-1,sizeof(int)*(n+1));
 for(int i=2;i<=n;i++){
 if(a[i]==-1){ con++;
 for(int j=i;j<=n;j=j+i) a[j]=0;}
}
return 0;
}