Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

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

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

C++: #include <iostream>
using namespace std;
int main(){
	int x = 1000000;
	int p[x],q[x];
	for(int i=2;i<x;i++) p[i] = 0;
	for(int i=2;i<x;i++){
		if(q[i]==0) for(int j=2;j<x/i;j++) q[i*j] = 1;
	}
	int c = -1;
	for(int i=2;i<x;i++){
		if(q[i]==0){
			c++;
			p[c] = i;
		}
	}
	int n;
	while(cin >> n){
		int a = 0;
		for(int i=0;i<c;i++){
			if(p[i]>n) break;
			a++;
		}
		cout << a << endl;
	}
}

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

#define LIM 1000000
using namespace std;

void prime();

vector<int> prime_map;

int main(){
  int num, i=0,j=0;
  vector<int> count;
  prime();
  cout<<"plese"<<endl;
  while(cin){
    cin>>num;
    i=0;
    while(prime_map[i]<=num){
      i=i+1;
    }
    count.push_back(i);
    j++;
  }

  i=0;
  while(i<j){
    cout<< count[i]<<endl;
    i++;
  }
}

void prime(){
  bool judge;
  for(int i = 2; i <= LIM;i++){
    judge=1;
    for(int j= 2; j < i/2; j++){
      if(i%j == 0){judge = 0;
 break;
}
    }
    if(judge == 1)prime_map.push_back(i);
  }
}

C++: 
#include<iostream>
using namespace std;
int n;
bool isPrime(int a){
	int i;
	for (i = 2; i < a; ++i){
		if (a%i == 0){
			return false;
		}
	}
	return true;
}
int main()
{
	while (cin >> n){
		for (int i = 2; i <= n; ++i){
			if (isPrime(i))
				cout << i << endl;
		}
	}
	return 0;
}

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

int main(){
int n,a;
int pri[99999];
pri[0]=2;
int ans=1;
while(cin>>n){
ans=1;
for(int i=3;i<n+1;i++){
pri[ans]=i;
for(int j=0;j<ans&&pri[j]*pri[j]<i+1;j++){
a=i%pri[j];
if(a==0){
ans--;
break;}
}
ans++;
}
if(n==1){ans=0;}
cout<<ans<<endl;}}

C++: #include <iostream>
#include <vector>
//#include <math.h>
//#include <string>
#include <cmath>

int main(void);
int count_prime_number(int n);

int main(){
	int n;
	int cnt = 0;
	//int result[30];
	std::vector<int> result;

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		//result[cnt] = count_prime_number(n);
		result.push_back(count_prime_number(n));
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
inline int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i+= 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j+= 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

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


#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repback(i,n) for(int i=(int)n-1;i>=0;i--)
#define repa(i,a,n) for(int i=a;i<(int)(n);i++)
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 1e7, MAX_N = 1000000, MAX_M = 1000, MAX_W = 20, MAX_H = 20;
int asc(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int is_prime[MAX_N]; //i番目の素数
bool prime[MAX_N]; //iが素数であるかどうか

int seive(int n) {
    rep(i, n+1) prime[i] = true;
    prime[0] = prime[1] = false;
    int p = 0;
    repa(i,2,n+1) {
        if (prime[i]) {
            is_prime[p++] = i;
            for (int j = i * 2; j <= n; j += i) prime[j] = false;
        }
    }
    return p;
}
int main() {
    int n;
    while (cin >> n) {
        int ans = seive(n);
        cout << ans << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

bool Is_Prime(int n){
  if(n==1) return false;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      return false;
    }
  }
  return true;
}
vector<int> prime;

signed main(){
  LOOP(i,1,1000000){
    if(Is_Prime(i))prime.PB(i);
  }
  int n;
  while(cin>>n){
    int ans=0;
    REP(i,prime.size()){
      if(prime[i]<=n)ans++;
      else break;
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <vector>

int main(int argc, char *argv[]) {
	using namespace std;
	
	int line;
	while (EOF != fscanf(stdin, "%d", &line)) {
		vector<bool> sieve(line, true);
		int prmCount = 0;

		for (int i = 2; i <= line; i++) {
			if (sieve[i]) {
				prmCount++;
				for (int j = i+i; j <= line; j+=i) {
					sieve[j] = false;
				}
			}
		}
		printf("%d\n", prmCount);
	}
	

	return 0;
}

C++: #include <iostream>

using namespace std;

#define M 10000000
bool prime[M];
int main()
{
	
	int ans, n;

	for (int i = 2; i * i < M; i++){
		if (prime[i] == false){
			for (int j = i; j < M; j += i){
				if (!(i == j)) {
					prime[j] = true;
				}
			}
		}
	}
	while (cin >> n){
	  ans = 0;
		for (int i = 2; i <= n; i++){
			if (prime[i] == false) ans++;
	  }
		cout << ans << endl;
	}
	return (0);
}

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

int main() {
	int n, count;
	bool *data;

	while (cin >> n) {
		data = new bool[n + 1];
		count = 0;
		for (int i = 0;i <= n;i++) data[i] = true;
		for (int i = 2;i <= n;i++) {
			if (data[i]) {
				count++;
				for (int j = i + i;j <= n;j += i) {
					data[j] = false;
				}
			}
		}
		cout << count << endl;
		delete[] data;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX_N 999999 + 16
 
int  prime[MAX_N];          
bool is_prime[MAX_N + 1];   
int sieve(const int& n)
{
    int p = 0;
    fill(is_prime, is_prime + n + 1, true);
    is_prime[0] = is_prime[1] = false;
    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()
{
    int n;
    while (cin >> n)
    {
        cout << sieve(n) << endl;
    }
    return 0;
}

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

int main() {
	static bool cmp[1000000] = { true };
	static int npr[1000000];
	for (int i = 2; i<1000000; i++) {
		if (!cmp[i]) {
			for (int j = 2; j*i<1000000; j++) {
				cmp[i*j] = true;
			}
		}
		npr[i] = npr[i - 1] + !cmp[i];
	}
	int n;
	while (cin >> n) {
		cout << npr[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=false;
      v[1]=false;
    for(int i = 2;i<MAX;i++){
      if(v[i]==true){
        for(int j = i;j<MAX;j=j*j){
         v[j]=false;
       }
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      cout << v[a]<<endl;
    }
}

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