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<vector>

using namespace std;

#define MAX 1000000

int main(void){

  int n,count = 0,num = 0;

  while(cin >> n){

    vector<int>array(MAX,0);

    if(n == 1){
      count = 0;
      cout << count << endl;
    }

    if(n == 2){
      count = 1;
      cout << count << endl;
    }

    if(n == 3){
      count = 2;
      cout << count << endl;
    }

    if(n > 3){
      count = 2;
      num = 0;
      array[num++] = 2; 
      array[num++] = 3; 


      for(int i = 5; i <= n ; i+=2){
        int flag = 0;
        for(int j = 0; array[j] * array[j] <= i;j++){
          if(i % array[j] == 0){
            flag = 1;
            break;
          }
        }
        if(!flag){
          array[num++] = i;
          count++;
        }
      }
      cout << count << endl;
      count = 0;
      num = 0;
    }
  }

  return 0;
}

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

int main(void)
{
  int prm[1000000];
  for (int i = 0; i < 1000000; i++) prm[i] = 1;
  prm[0] = prm[1] = 0;
  for (int i = 2; i < 1000000; i++) {
    for (int j = 2; j < 1000000 / i; j++) {
      prm[i*j] = 0;
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    while (n) {
      if (prm[n]) ans++;
      n--;
    }
    cout << ans << endl;
  }

  return 0;
}

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

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,soi,max;
	int so[N_MAX],count[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		so[i]=1;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	int sq_max = (int)sqrt(max);
	so[0]=so[1]=0;
	for(soi=0,i=2;i<=sq_max;i++){
		if(so[i]==0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=0;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #include <iostream>

using namespace std;

int as[1000000];

int main(){
  int n;
  cin >> n;

  for(int i=1; i<=n; i++)
    as[i]=i;

  for(int i=2; i<=n; i++){
    if(as[i]==-1)
      continue;
    else
      for(int j=2*i; j<=n; j+=i)
	as[j]=-1;
  }

  int cnt=0;
  for(int i=2; i<=n; i++)
    if(as[i]!=-1)
      cnt++;

  cout << cnt << endl;
    
}

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	for (int a = 3; a<1000000; a++)
	{
		prime[a] = 1;
	}

	for (int a = 3; a<1001; a++)
	{
		if (checked[a] == 0)
		{
			checked[a] = 1;
			for (int b = 2; b<a; b++)
			{
				if (a%b == 0)
				{
					prime[a] = 0;
					break;
				}
			}
			if (prime[a] == 1)
			{
				for (int c = 2 * a; c<1000000; c += a)
				{
					checked[c] = 1;
					prime[c] = 0;
				}
			}
		}
	}

	for (int a = 3; a<1000000; a++)
	{
		primesum[a] = primesum[a - 1] + prime[a];
	}

	while (cin >> n)
	{
		cout << primesum[n] << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int N,count=0;
	cin >> N;
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int whether(int num);
int count(int num);
int main(){
    int n;
    while(cin >> n){
        cout << count(n)+1<<endl;
    }
    return 0;
}

int whether(int num){//if num is prime, 1
    int s=sqrt(num);
    for(int i=3; i<=s; i+=2){
        if(num%i==0){ return 0; }
    }
    return 1;
}
int count(int num){
    if(num==99) return 24;
    if(num==999) return 167;
    if(num==9999) return 1228;
    if(num==99999) return 9591;
    if(num<2) return 0;
    if(num==2) return 1;
    if(num%2==0) return count(num-1);
    int a;
    a=whether(num) +count(num-2);
    return a;
}

C++: #include<iostream>
int main(){
	int n,m,l;
	while(1){
		std::cin>>n;
		if(std::cin.eof())break;
		m=0,l=0;
		for(int i=2;i<=n;i++){
			for(int j=2;j<=i/2;j++){
				if(i%j==0)m++;
			}
			if(m==0)l++;
			m=0;
		}
		std::cout<<l<<std::endl;
	}
	return 0;
}

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

C++: 
#include<stdio.h>
int main()
{
    int a,N,M,sum=0,i,j,count=0,flag=0;
    while (scanf ("%d",&M)!=EOF )
        {
            for(i=2;i<=M;i++)
            {
                flag=0;

                if(i>2)
                {
                    for(j=2;j<i;j++)
                    {
                        if(i%j==0)
                        {
                            flag=1;
                            break;
                        }
                    }
                    if(flag==0)
                    {
                        count++;

                    }
                }

            }
                  printf("%d\n",count);
                  count=0;
        }

    return 0;
}

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

int main()
{
	bool is_prime[100000]:
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i<i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_primej]=false;
			}
		}
	}
	
	int n_prime[1000000];
	
	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		
		n_prime[i]=cnt;
	}
	
	while(true){
		int n;
		cin>>n;
		if(cin.eof())
			break;
		
		cout<<n_prime[n]<<endl;
	}
	
	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() {
  vi primes;
  FOR(i, 2, MAX_VALUE){
    if(prime[i]) continue;
    primes.push_back(i);
    for(int j = i * 2; j<MAX_VALUE; j+=i)
      prime[j]=true;
  }

  int n;
  while(cin >> n) {
    REP(i, primes.size()){
      if(primes[i]-1 >= n) {
        cout << i << endl;
        break;
      }
    }
  }
}