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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	int n, p, k, count;
	vector<int> num(1000000, 1);
	while(cin>>n){
		count=0;
		num[0]=0; num[1]=0;
		for(int i=4; i<=n; i+=2){
		num[i]=0;
		}
		for(int i=0; i<=n; i++){
			p = i+i+3;
			for(k=p+p; k<=n; k+=p){
				num[k]=0;
			}
		}
		for(int i=0; i<=n; i++){
			if(num[i]==1)
				count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

bool isPrimes[1000000];

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

	return 0;
}

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;
	}
}