Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

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

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    int prime[100000];
    long long ptr = 0;

    prime[ptr++] = 2;
    prime[ptr++] = 3;

    while (cin >> n) {
        if (n <= 1) {
            cout << "0\n";
            continue;
        }
        else if (n == 2) {
            cout << "1\n";
            continue;
        }
        else if (n == 3) {
            cout << "2\n";
            continue;
        }

        int count = 2;        
        for (int i = 5; i <= n; i += 2) {
            bool flag = false;
            for (int j = 1; prime[j] * prime[j] <= i; j++) {
                if (!(i % prime[j])) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                prime[ptr++] = i;
                count++;
            }
        }
        cout << count << "\n";
    }
    
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(void){
  int n;
while(cin>>n){
  vector<bool> nature(n,true);
  nature[0]=nature[1]=false;
  for(int i=0;i*i<=n;i++){
if(nature[i]){
  for(int j=2;j<=n/i;j++)
  nature[i*j]=false;
}
  }
int count=0;
for(int i=0;i<=n;i++)
if(nature[i])
count++;
cout<<count<<endl;
}
return 0;
}

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

int main(void)
{
	int number = 0;
	int count = 0;

	while(cin >>  number){
		count = 0;
		for(int i=2;i<=number;i++){
			for(int j= 2 ;j<=i/2;j++){
				if(i % j == 0){//割り切れる＝素数じゃない
					goto go;
				}
			}
			count++;
go:
		;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int prime(int n);
int main(){
	int count=0;
	int n;
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",prime(n));
	}
	return 0;
}

int prime(int n){
	int i,j;
	int p=0;
	int count=0;
	for(i=2;i<=n;i++){
		for(j=2;j<i;j++){
			if(i%j==0)p++;
		}
		if(p==0)count++;
		p=0;
	}
	return count;
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i=3;
	while( i <= sqrt(x) ){
		if(x%i==0)return 0;
		i = i + 2;
	}
	return 1;
}
int main(){
	int n,c,i;
	while(scanf("%d",&n)!=EOF){
		c=1;
		for(i=3;i<=n;i+=2)if(isprime(i))c++;
		printf("%d\n",c);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int n;
bool prime[1000000];

int main() {

	for (int i = 2; i <= 1000000; i++) prime[i] = true;

	for (int i = 2; i <= 1000000; i++) {
		if (!prime[i]) continue;
		for (int j = 2; i * j <= 1000000; j++) {
			prime[i * j] = false;
		}
	}

	n = -1;
	cin >> n;

	while (n != -1) {
		int cnt = 0;
		for (int i = 2; i <= n; i++) {
			if (prime[i]) cnt++;
		}
		cout << cnt << endl;

		n = -1;
		cin >> n;
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

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

int main() {
	int n, c;

	while (std::cin >> n) {
		std::vector<int> nums;
		++n;
		c = 0;
		for (int i = 0; i < n; ++i) {
			nums.push_back(i);
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) < 2) continue;
			for (int j = nums.at(i) * 2; j < n; j += nums.at(i)) {
				nums.at(j) = 0;
			}
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) > 1) {
				++c;
			}
		}
		std::cout << c << std::endl;
	}
	return 0;
}