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>
#include<algorithm>
using namespace std;
 
int main(){
  bool prime[1000000] = {};
  int sum[1000000]; sum[0] = sum[1] = 0; sum[2] = 1;
  for(int i = 3 ; i < 1000000 ; i += 2 ){
    sum[i] = sum[i + 1] = sum[i - 1];
    if(!prime[i]){
      for(int j = i + i + i ; j < 1000000 ; j += i + i ){
        prime[j] = true;
      }
      sum[i]++;
      sum[i+1]++;
    }
  }
 
  int n;
  while(cin >> n){
    cout << sum[n] << endl;
  }
}

C++: #include <iostream>
#include <cstring>
using namespace std;
#define maxn 1000000

int  isprime(int n)
{
  
  bool prime[maxn];
  int p = 0;
  memset(prime,true,sizeof(prime));
  prime[0] = prime[1] = false;
  for(int i=2;i<=n;i++)
  {
    if(prime[i])
    {
      for(int j=2*i;j<=n;j+=i) prime[j] = false;
      p++;
    }
  }

  return p;
}

int main()
{

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

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
bool ifprime(int i);
int numbers[31];
int nn[31];
int num = 0;
int main()
{
	int n, count;
	bool ans;
	while ((scanf("%d", &n)) != EOF)
	{
		if (num > 0)
		{
			for (int i = 0; i <= num; i++)
			{
				if (n == numbers[i])
				{
					printf("%d\n", nn[i]);
					break;
				}
			}
		}
		else
		{
			count = 0;
			for (int i = 2; i <= n; i++)
			{
				ans = ifprime(i);
				if (ans == true)
				{
					++count;
				}
			}
			printf("%d\n", count);
			numbers[num] = n;
			nn[num] = count;
			num++;
		}
	}

	return 0;
}
bool ifprime(int i)
{
	int m = (int)sqrt(i);
	for (int j = 2; j <= m; j++)
	{
		if (i% j == 0)
		{
			return false;
		}
	}
	return true;
}

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

static bool sieve[1000010];
static int primecount[1000010];

int main() {
	fill(sieve, sieve+1000010, true);
	sieve[0]=sieve[1]=false;
	primecount[0]=primecount[1]=0;
	int partial_count = 0;
	for(int i = 2; i < 1000010; i++) {
		primecount[i] = partial_count;
		if(!sieve[i])continue;
		primecount[i] = ++partial_count;
		if(i<10000)
			for(int j = i*i; j < 1000010; j+=i) {
				sieve[j]=false;
			}
	}
	while(true) {
		int n; if(scanf("%d", &n)<1)break;
		printf("%d\n", primecount[n]);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int prime[80000];
    int ptr=2;
    prime[0] = 2;
    prime[1] = 3;
    for(int num=5; num<1000000; num+=2){
        bool f = false;
        for(int i = 0; i<ptr; i++){
            if (prime[i]*prime[i] > num) break;
            if (num%prime[i]==0) {
                f = true;
                break;
            }
        }
        if(!f) prime[ptr++] = num;
    }
    prime[ptr]=1000001;
    int n;
    while(cin >> n){
        int k=0;
        for(;prime[k]<=n;k++);
        cout << k << endl;
    }
     
    return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#define MAX_NUM 999999
int numbers[MAX_NUM] = {-1, -1};
int isPrime(int num) {
    int i;
    if(numbers[num]) {
        return 0;
    }
    for(i=num << 1; i<=MAX_NUM; i+=num) {
        numbers[i] = -1;
    }
    return 1;
}

int main() {
    int i, n, count;
    while(scanf("%d", &n) != EOF){
        count = 0;
        for(i=2; i<=n; ++i) {
            count += isPrime(i);
        }
        printf("%d\n", count);
    }
    return 0;
}

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

int main(void){
  int n;
  bool p[1000000];
  p[0] = p[1] = 0;
  p[2] = 1;
  int ans = 0;
  bool flag;
  for(int i = 0; i < 1000000; i++)
    p[i] = false;
  p[2] = true;
  for(int i = 3; i <= 1000000; i += 2){
    flag = true;
    for(int j = 3; j * j <= i; j += 2){
      if(i % j == 0){
	flag = false;
	break;
      }
    }
    if(flag)
      p[i] = true;
  }
  // cout << "end" << endl;
  while(cin >> n){
    int ans = 0;
    for(int i = 2; i < n; i++){
      if(p[i])
	ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    int maxy = (int)sqrt(100000);
    int prime[100000];
    for(int i = 0; i < 100000; i++){
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for(int i = 2; i <= maxy; i++){
        if(prime[i] == 1){
            for(int j=i*2; j <= maxy; j+=i){
                prime[j] = 0;
            }        
        }
    }
    int n;
    while(cin >> n){
        int ans = 0;
        for(int i=0; i <= n; i++){
            if(prime[i] == 1){
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
  int n,flag=1,sum = 0;

  while(cin >> n){

    for(int i=2; i <= n; i++){
      if(i != 2 && i%2 == 0) flag = 0;
      else if(i != 3 && i%3 == 0) flag = 0;
      else if(i != 5 && i%5 == 0) flag = 0;
      else{
	for(int j=3; j < i/2; j+2){
	  if(i%j == 0 ) flag = 0;
	}
      }
      if(flag == 1) sum++;
      flag = 1;
    }
    cout << sum <<endl;
    sum = 0;
  }
}

C++: #include <stdio.h>

const int MAX_V = 100000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

int main(){
    init();
    int num;
    while(scanf("%d", &num) != EOF){
        int count=0;
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_VALUE = 100007;
bool prime[MAX_VALUE];

int main() {
  FOR(i, 2, MAX_VALUE){
    if(prime[i]) continue;
    for(int j = i * 2; j<MAX_VALUE; j+=i)
      prime[j]=true;
  }

  int n;
  while(cin >> n) {
    int cnt = 0;
    FOR(i, 2, n + 1){
      if (!prime[i]) cnt++;
    }
    cout << cnt << endl;
  }
}