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 <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>

#define N 1000000L
bool num[N];

void furui(){
  long int i;
  int divide;
  int rt = (int) sqrt(N);
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for(divide = 2; divide <= rt; divide++){
    if(num[divide] == false) continue;
    for( i = divide; i < N; i+= divide){
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0; ;i++){
      c = getchar();
      if(c == EOF || c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == 1) count++;
    }
    std::cout << count << std::endl;
    if(c == EOF) break;
  }
  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    while (cin >> n) {
        if (n == 1) {
            cout << 0 << endl;
            continue;
        }
        
        vector<bool> is_prime(n + 1, true);
        is_prime[0] = false; is_prime[1] = false;
        for (int i = 2; i <= n; i++) {
            if (is_prime[i]) {
                for (int j = 2 * i; j <= n; j += i) {
                    is_prime[j] = false;
                }
            }
        }
        
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            if (is_prime[i]) ans++;
        }
        cout << ans << endl;
    }
    
    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
void eratosthenes(V &v) {
  v[0] = v[1] = false;
  loop(i, 2, v.size()) v[i] = true;
  for (int i = 2; i * i < v.size(); i++) {
    if (v[i]) {
      for (int j = i * 2; j < v.size(); j += i) {
        v[j] = false;
      }
    }
  }
}

void solve() {
  vi v(1000000);
  eratosthenes(v);
  loop(i, 1, v.size()) v[i] += v[i - 1];
  int n;
  while (cin >> n) cout << v[n] << endl;
}

C++: #include <cstdio>

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j-1] = true;
		}
	}
	for(int i = 1;i < 1000000;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	return 0;
}

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

int main(){
int n,a;
int pri[999999];
pri[0]=2;
int ans=1;
while(cin>>n){
for(int i=3;i<n+1;i++){
for(int j=0;j<ans;j++){
a=i%pri[j];
if(a==0){
break;}
if(j==ans-1){
pri[ans]=i;
ans++;
break;
}
}}
cout<<ans<<endl;}}

C++: #include <iostream>

using namespace std;

int pri(int n){
	int x = 0;
	int sum;
	
	for(int i = 1;i <= n;i++){
		sum = 0;
		for(int j = 1; j <= i; j++){
			if( i % j == 0) sum += j;
			if(sum == i + 1) x++;
		}
	}
	return x;
}

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

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

int main()
{
	int count=0,n;
	bitset<1000001> prime;

	prime[0]=1;
	prime[1]=1;
	for(int i=2;i<=1000;i++)
		if(prime[i]==0)
			for(int j=i+1;j<=1000000;j++)
				if(j%i==0)
					prime[j]=1;
	
	while(cin>>n)
	{
		for(int i=0;i<=n;i++)
			if(prime[i]==0)
				count++;
		cout<<count<<endl;
		count=0;
	}
		
}

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

bool primes[1000000+1];

void Sieve() {
    for(int i = 2; i < 1000000; i++) {
      primes[i] = true;
    }
    /* 素数でない整数を false にする */;
    primes[1] = false;
    for(int i = 2; i <= 1000; i++) {
        if(primes[i]) {
            int p = i;
            for(int j = p + p; j <= 1000000; j+=p) {
                primes[j] = false;
            }
        }
    }
}

bool IsPrime(int n) {
	return primes[n];
}

int main(void){
    int n;
	Sieve();
	while(cin >> n) {
	    int count = 0;
	    for(int i = 2; i <= n; i++) {
		    if(IsPrime(i)) {
            count += 1;
		    }
	    }
	    cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>
#include <array>
#include <utility>
#include <functional>

using namespace std;
typedef long long Int;
#define REP(i , x) for(int i = 0 ; i < x ; ++i)

typedef pair<int, int> P;

bool dp[10000100];

int main()
{
	int N;
	while (cin >> N){
		long ans(0);
		dp[0] = dp[1] = true;
		for (int i = 2; i*i <= N; ++i){
			if (!dp[i]){
				for (int j = 2*i; j <= N; j += i)
					dp[j] = true;
			}
		}
		for (int i = 2; i <= N; ++i){
			ans += !dp[i];
		}
		cout << ans << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
const int MAX=1e6+5;
bool shibushi[MAX];
int counts[MAX];
void isprime()
{
	memset(shibushi,true,sizeof(shibushi));
	int c=0;
	counts[1]=0;
	for(int i=2;i<MAX;i++)
	{
		if(shibushi[i])
		{
			counts[i]=++c;
			for(int j=2*i;j<MAX;j+=i)
			shibushi[j]=false;
		}
		else counts[i]=c;
	}
}
int main()
{
	isprime();
	while(cin>>n)
	{
		if(n<=0) cout<<0<<endl;
		else cout<<counts[n]<<endl;
	}
	return 0;
}