Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

int main(){
	long long n=0,i,g,count=0;
	bool p=false;
	while(scanf("%d",&n)==1){
	for(g=2;g<=n;g++){
		for(i=2;i<g;i++){
			if(g%i==0){
				p=true;
				break;
			}
		}
		if(p) p=false;
		else{
			count++;
			p=false;
			}
		}
	printf("%d\n",count);
	count=0;
	}
	return 0;
}

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

int main()
{
	
	long int k,p[100000];
	float n;
	p[0]=2;
	while(cin>>n){
	k=0;
	int r=(int)sqrt(n);
	for(int i=3;i<=r;i++){
		for(int j=0;j<k+1;j++){
			if(i%p[j]==0){
				break;
			}else if(j==k){
				k++;
				p[k]=i;
			}
		}
	}
	int r_k=k;
	for(;r<n;r++){
		for(int i=0;i<=r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==r_k){
				k++;
			}
		}
	}
	if(k!=0&&k!=1){
	cout<<k+1<<endl;
	}else{
		cout<<k<<endl;
	}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include<algorithm>
#define pf printf
#define sf scanf

using namespace std;

bool isprime(int n){
	if(n < 2)return false;
	for(int i=2;i*i<=n;i++)
		if( n%i == 0)return false;
	return true;
}

int main()
{
    int n;
	bool arr[1000000] = {false};
	for(int i=0;i<1000000;i++){
		arr[i] = isprime(i);
	}
	while(cin >> n){
		int coun=0;
		for(int i=0;i<=n;i++){
			if(arr[i]==true)coun++;
		}
		printf("%d\n",coun);
	}
    return 0;
}

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

using namespace std;

#define MAX 1000000

int p[MAX];

void fanc(void){
	int num = 0;
	for(int ix = 2;ix < MAX;++ix){
		if(p[ix] == 0){
			p[ix] = ++num;
			for(int jx = 2;jx*ix<MAX;++jx)
				p[jx*ix] = -1;
		}else
			p[ix] = num;
	}
}

int main()
{
	int n;
	fanc();
	while(cin >> n)
		cout <<p[n]<<endl;

	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int count;
	while (1)
	{
		cin >> n;
		if (cin.fail()) break;

		bool *isPrime;
		isPrime = new bool[n + 1];
		memset(isPrime, true, sizeof(bool) * (n + 1));
		isPrime[0] = isPrime[1] = false;
		
		count = 0;
		for (int i = 2; i <= n;++i)
		{
			while (isPrime[i] != true)
			{
				++i;
				if (i > n) break;
			}

			for (int j = i + i; j <= n; j += i)
			{
				isPrime[j] = false;
			}
		}
		for (int i = 0; i <= n; ++i)
		{
			if (isPrime[i] == true)
				++count;
		}
		cout << count << endl;
		delete[] isPrime;
	}
	return 0;
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
const int Max=10000000;
bool prime[Max];
int main(void){
    int in;
    for(int i=0;i<Max;i++)prime[i]=true;
    prime[1]=false;
    for(int i=2;i<Max;i++){
        if(prime[i]){
            for(int s=i*2;s<=Max;s+=i)prime[s]=false;
        }
    }
    while(cin>>in){
        int cnt=0;
        for(int i=1;i<=in;i++){
            if(prime[i])cnt++;
        }
        cout << cnt << "\n";
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int flg[1000000];
int main(void)
{
	int n,i,j,cnt;
	while(scanf("%d",&n)!=EOF){
		for(i=2;i<=n;i++) flg[i]=1;
		for(i=2;i*i<=n;i++){
			if(flg[i]==1){
				for(j=2;i*j<=n;j++){
					flg[i*j]=0;
				}
			}
		}
		cnt=0;
		for(i=2;i<=n;i++){
			if(flg[i]==1) cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<int> v;
    v.resize(n + 1);
    fill(v.begin(), v.end(), 1);
    v[0] = 0;
    v[1] = 0;
    for (int i = 0; i * i < v.size(); ++i) {
      while (v[i] == 0) ++i;
      for (int m = i + 1; m < v.size(); ++m) {
        if (m % i == 0) {
          v[m] = 0;
        }
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int a,b,c=0;
	while(scanf("%d",&a)!=EOF){
		for (int A=2;A<=a;A++){
			for (int B=2;B<=A;B++){
				b=A%B;
				if (A==B){
					c++;
					break;
				}
				if (b==0) break;
			}
		}
		cout<<c<<endl;
		c=0;
	}
	return 0;
}

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

void count_Prime(int n);
int IsPrime(int num);


int main()
{
	int Data = 0;
	while (cin >> Data)
	{
		count_Prime(Data);
	}

	return 0;
}

void count_Prime(int n)
{
	int counter = 0,  i = 0;
	for (i = 2; i < n; ++i)
	{
		counter += IsPrime(i);		
	}

	cout << counter << endl;

}

int IsPrime(int num)
{
	if (num < 2) return 0;
	else if (num == 2) return 1;
	else if (num % 2 == 0) return 0; // ??¶??°????????????????????????

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return 0;
		}
	}

	// ?´???°??§??????
	return 1;
}

C++: #include <iostream>
 
 int main() {
     int n;
     while (std::cin >> n) {
        int primes = 0; // n以下の素数の数
         for (int i = 2; i <= n; i++) {
               bool flag = false; // はずれの目印
               for (int j = 2; j < i; j++)
                 if (!(i % j)) {
                     flag = true;
                    break;
                  }
              if (!flag)
                  primes++;
          }
          std::cout << primes << std::endl;
      }
  }

C++: 
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		while(true){
			Scanner sc=new Scanner(System.in);
			int INF=1000;
			int cnt=0;
			int n=sc.nextInt();
			int[] prime=new int[n+1];
			for(int i=0;i<=n;i++){
				prime[i]=INF;
			}
			for(int i=2;i<=n;i++){
				if(prime[i]==INF&&n%i==0){
					prime[i]=0;
					cnt++;
					for(int j=2;j*i<=n;j++){
						prime[j*i]=1;
					}
				}
			}
sc.close();
			System.out.println(cnt);
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int a,t[1000000],u[1000000];
  for(int i=0;i<1000000;i++){
    t[i]=1;
  }
  t[0]=t[1]=u[0]=u[1]=0;
  for(int i=2;i<=1000000;i++){
    if(t[i]==1){
      for(int j=i+i;j<1000000;j+=i)t[j]=0;
      u[i]=u[i-1]+1;
    }else{
      u[i]=u[i-1];
    }
  }
  while(cin>>a){
    cout<<u[a]<<endl;
  }
  return 0;
}

C++: // 6/2
// 2-6-4. 素数のこすう
// エラトステネスの篩
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

// const int MAX_N = 1000000;

vector<int> prime;  // i番目の素数
vector<bool> is_prime;  // iが素数かどうか

void sieve(int n) {
    // 一旦全ての数字を素数に。
    prime.resize(n, 0);
    is_prime.resize(n + 1, true);

    // 0, 1は素数では無い。
    is_prime[0] = is_prime[1] = false;

    int p = 0;

    for (int i = 2; i < n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }

    // return p;
}

int main() {
    sieve(1e6);

    int n;
    vector<int> ans;

    while (cin >> n) {
        int an = 0;
        rep(i, n + 1) {
            if (is_prime[i]) an++;
        }
        ans.push_back(an);
    }

    for (auto a : ans) cout << a << endl;
}