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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

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

C++: #include<stdio.h>
#define MAX_V 1000000
int prime[MAX_V + 1];
int sum[MAX_V + 1];
int main(){
  int n, i, k;
  /*??¨????????????????????????*/
  prime[0]=prime[1]=0;
  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;
      }
    }
  }
  /*?´???????*/
  sum[0] = 0;
  for(i = 0;i < MAX_V;i++){
    sum[i+1] = sum[i]+prime[i+1];
  }
  /*?´???°?????°???????????????*/
  while(scanf("%d", &n) == 1){
    printf("%d\n", sum[n]);
  }
  printf("%d %d %d\n", n,prime[MAX_V], sum[MAX_V]);
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = int(1e6) + 5;

uint64_t flag[MAX_N];


void set_f(uint64_t i){
    flag[i>>6] &= ~(1ULL<<(i&((1ULL<<6)-1)));
}

bool get_f(uint64_t i){
    return ((flag[i>>6]>>(i&((1ULL<<6)-1)))&1);
}

void sieve(const int64_t n){
    const uint64_t siz = n/2, sqrtN = ceil(sqrt(n)+0.1)/2;
    fill(flag, flag+(siz>>6)+1, -1);
    for(uint64_t i=1ULL; i<=sqrtN; ++i){
        if(get_f(i)){
            const uint64_t p = 2*i+1;
            for(uint64_t j = 2*i*(i+1); j<=siz; j+=p){
                set_f(j);
            }
        }
    }
}

bool isPrime(int n){
    if(n == 2) return true;
    else return n&1 && get_f(n/2);
}

int cum[MAX_N]{};

int main() {
    sieve(MAX_N);
    for(int i=2;i<MAX_N;i++){
        if(isPrime(i))cum[i]++;
        cum[i] += cum[i-1];
    }
    int n;
    while(cin >> n){
        cout << cum[n] << endl;
    }
    return 0;
}

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

bool Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = false;
	for (int i = 0; i < 1000000; i++){
		Eratos[i] = true;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = false;
			}
		}
	}
	int n,res;
	while (scanf("%d", &n)) {
		res = 0;
		for (int i = 0; i < n; i++) {
			if (Eratos[i])
				res++;
		}
		printf("%d\n",res);
	}
	return 0;
}

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

using namespace std;

#define REP(a, i, n) for (int i = a; i <= n; ++i)

bool isPrime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    if (n == 3) return true;
    if (n % 3 == 0) return false;

    for (int i = 5; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

//  n よりも小さい素数の数は何個存在するか
int main() {

    int n = 0; // 999,999
    while(scanf("%d", &n) != EOF) {
        int cnt = 0;
        REP(1, i, n) {
            if (isPrime(i)) cnt++;
        }

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

    return 0;
}

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

using namespace std;

int main() {
  bitset<1000000> primes;
  int i, j, n, ans;
  while (cin >> n) {
    primes.reset();
    for (i = 2; i <= n; i++)
      if (primes[i] == false)
	for (j = i + i; j <= n; j += i)
	  primes[j] = true;
    cout << (n == 0 ? 0 : n - primes.count() - 1) << endl;
 }
  return 0;
}

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

int main() {
	std::vector<bool> isPrime(1000000, true);
	std::vector<int> numP(1000000, 0);

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

	for (int i = 2; i < 1000000; i++) {
		if (isPrime[i]) {
			numP[i] = numP[i - 1] + 1;
			for (int x = 2; i*x < 1000000; x++) {
				isPrime[i*x] = false;
			}
		}
		else {
			numP[i] = numP[i - 1];
		}
	}

	int input;
	while (std::cin >> input) {
		std::cout << numP[input] << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,count=0;
  while(scanf("%d",&n)!=EOF){
    if(n==0 || n==1){
      return 0;
    }
    int data[n+1];
    for(int i=2;i<=n;i++){
      data[i]=0;
    }
    for(int i=2;i<=n;i++){
      if(data[i]!=-1){
	count++;
	for(int j=i;j<=n;j+=i){
	  if(data[j]!=-1){
	  data[j]=-1;
	  }
	}
      }
    }
    cout << count << endl;
    count=0;
  }
  return(0);
}

C++: #include<stdio.h>
#include<math.h>
int main(void) {
	int prime[1000000] = { 0 }, n, sum = 0;;
	prime[1] = 1;
	while (scanf("%d", &n) != EOF) {
		for (size_t i = 2; i <= sqrt(n); i++)
		{
			if (prime[i] == 0)
			{
				for (size_t t = i + 1; t <= n; t++)
				{
					if (t%i == 0)prime[t] = 1;
				}
			}
		}
		for (size_t i = 2; i <= n; i++)
		{
			if (prime[i] == 0)sum++;
		}
		printf("%d\n", sum);
		sum = 0;
	}
	return 0;
}

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

void cnt(int i) {
	int j,k,l,m;
	l=0;
	m=0;
	for(j=1;j<=i;j++){
		for(k=1;k<=sqrt(j)+1;k++){
			if(j%k == 0){
				l++;
			}
		}
		if(l == 2){
			m++;
		}
		l=0;
	}
	printf("%d\n",m);
}

int main(void){
	int i;
	while (scanf("%d", &i) != EOF){
		cnt(i);
	}
}

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

int prime(int n){
  long long cnt=0;
  bool f[n+1];
  for(int i=0;i<=n;i++){
    f[i]=true;
  }
  f[0]=f[1]=false;
  for(int i=2;i<=n;i++){
    if(f[i]){
      cnt++;
      for(int j=2*i;j<=n;j+=i){
        f[j]=false;
      }
    }
  }
  return cnt;
}

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

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

bool isprime[1000000];

int main(int argc, char **argv){
	int n;
	int cnt;
	int checkcnt = 0;
	for (int i = 0; i < 1000000; i++) {
		isprime[i] = true;
	}
	while (cin >> n && checkcnt < 30) {
		cnt = 0;
		int i;
		for (i = 2; i < sqrt(n); i++) {
			if (isprime[i]) {
				for (int j = 2; j <= n / i; j++) {
					isprime[i * j] = false;
				}
			}
		}
		for (int k = 2; k <= n; k++) {
			if (isprime[k]) {
				cnt++;
			}
		}
		cout << cnt << endl;
		checkcnt++;
	}
	return 0;
}

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

bool isPrime(int x) {
  if(x == 2) {
	return true;
  }
  
  if(x < 2 || x % 2 == 0) {
	return false;
  }
  for(int i = 3; i <= (int)sqrt(x); i += 2) {
	if(x % i == 0) {
	  return false;
	}
  }
  return true;
}

int main() {
  int n;
  bool a[1000000];

  for(int i = 1; i < 1000000; ++i) {
	if(isPrime(i)) {
	  a[i] = true;
	}
  }
  /*
  for(int i = 1; i < 10000; ++i) {
	if(isPrime(i)) {
	  cout << i << " ";
	}
  }
  */
  while(cin >> n) {
	cout << accumulate(&a[1], &a[n + 1], 0) << endl;
  }
  return 0;
}

/*-- primitive algorithm --*/
/*
bool isPrime(int n) {
  for(int i = 2; i < n; ++i) {
	if(n % i == 0) return false;
  }
  return true;
}
*/