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<cstdio>
#include<iostream>
using namespace std;
int main(){ 
    int n;
    int prime[1000000];
    while(cin>>n){
    for(int i=0;i<1000000;i++)prime[i]=0;
    for(int i=2;i<=n;i++){ 
        for(int j=2;i*j<=n;j++){ 
            prime[i*j]=1;
        }
    }
    int ans=0;
    for(int i=2;i<=n;i++){
        if(prime[i]==0)ans++;
    }
    printf("%d\n",ans);
    }
}

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

#define pb push_back

using namespace std;

const int MAX=100000;
int main(void)
{
	int x;
	bool p[MAX];
	int cnt;
	int i1,i2;

	fill(p,p+MAX,false);

	for(i1=2;i1<MAX;i1++){
		for(i2=2;i2*i2<=i1;i2++){
			if(i1%i2==0) break;
		}
		if(i2*i2>i1) p[i1]=true;
	}

	while(1){
		cin>>x;
		if(cin.eof()) break;

		cnt=0;
		for(i1=0;i1<=x;i1++){
			if(p[i1]) cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void)
{
    int n;
    while (cin >> n)
    {
        int c = 0;
        for (int i = 2; i <= n; i++)
        {
            int t = 1;
            for (int j = 2; j < i; j++)
            {
                if (i % j == 0)
                {
                    t++;
                }
            }
            if (t == 1)
            {
                c++;
            }
        }
        cout << c << endl;
    }
}

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

int main() {
    long in, out;
    int p, count;
    
    do{
         cin >> in;
         out = 0; 
         
         for(int i = 1; i <= in; i++)
         {
                 count = 0;
                 for(p = 1; p <= i; p++)
                 {
                       if(i % p == 0){
                            count++;
                            }
                 }
                 
                 if(count == 2){
                          out++;
                 }
         }
         
         cout << out << endl;
         
    }while(in);  
    

    return 0;
}

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

using namespace std;

#define MAX_N 99999
#define MAX_D 30

bool prime_check(int n, int k = 2)
{
	if (n < k * k) { return true; }

	if (n % k == 0) { return false; }

	return prime_check(n, k + 1);
}

int main()
{
	int n;

	bool isprime[MAX_N + 1];

	for (int i = 2; i < MAX_N + 1; i++)
	{
		isprime[i] = prime_check(i);
	}

	while (cin >> n)
	{
		cout << count(isprime + 2, isprime + n + 1, true) << endl;
	}

	return 0;
}

C++: #include<stdio.h>

int main(void){
  int n;
  while(scanf("%d",&n)!=EOF){
    if(n==1){
      printf("%d\n",0);
      break;
    }
    int p[1000000];
    p[0]=2;
    int pi=1;
    int i=2;
    while(i<=n){
      int t=1;
      int j;
      for(j=0;j<pi;j++){
	if(i%p[j]==0){
	  t=0;
	  break;
	}
      }
      if(t==1){
	p[pi]=i;
	pi++;
      }
      i++;
    }
    printf("%d\n",pi);
  }
  return 0;
}

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

int main(){
  int prime[100000];
  int isprime[1000000];
  memset(isprime,1,sizeof(isprime));
  isprime[0]=0;
  isprime[1]=0;
  
  for(int i=2;i<1000000;i++){
    if(isprime[i]){
      for(int j=i*2;j<1000000;j+=i){
	isprime[j]=0;
      }
    }
  }
  int pi;
  for(int i;i<1000000;i++){
    if(isprime[i]==1){
      prime[pi]=i;
      pi++;
    }
  }

  int n;
  while(cin>>n){
    int ans;
    while(prime[ans]<=n){
      ans++;
    }
    cout<<ans<<'\n';
  }
  return 0;
}

C++: #include<cstdio>
using namespace std;
const int N = 1000000;

int main(){

  int IsPrime[N];
  IsPrime[0] = -1;
  IsPrime[1] = -1;
  for(int i=2; i*i<=N;i++){
    if(IsPrime[i]==0){
      IsPrime[i] = 1;
      for(int j=2*i; j<=N; j+=i)
        IsPrime[j] = -1;
      }
  }
  int max;
  while(~scanf("%d",&max)){
    int count=0;
    for(int i=1; i<max+1; i++)
      if(IsPrime[i]==1) count++;
    printf("%d\n",count);
  }
}

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

using namespace std;
int sieve[1000005]= {0}, n, i, j, cnt=0;;
int main()
{
    while(cin>>n)
    {
        cnt=0;
        for(i=2; i<=n+2; i++)
        {
            if(!sieve[i])
            {
                for(j=2*i; j<=n+1; j+=i)
                {
                    sieve[j]=1;
                }
            }
        }

        for(i=2; i<=n; i++)
        {
            if(!sieve[i])
            {
                cnt++;
            }
        }
        cout<<cnt<<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<iostream>
#include<cstdio>
using namespace std;

int main() {
	int n;
	while(cin >> n && n != EOF) {
		bool* prime = new bool[n+1];
		int count = 0;
		for(int i = 2; i < n; ++i) {
			prime[i] = true;
		}
		prime[0] = prime[1] = false;
		
		for(int i = 0; i < n; ++i) {
			if(prime[i]) {
				count++;
				for(int j = 2 * i; j < n; j += i) {
					prime[j] = false;
				}
			}
		}
		
		cout << count << endl;
		delete[] prime;
	}
}