Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

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

int main(){
	int n;
	int count=0;
	int prime_num=0;
	while(cin >> n){
		for(int i=1;i <=n;i++){
			count = 0;
			 for(int j=1;j<=i;j++){
				if(i%j == 0) count ++;
			 }
			 if(count == 2) prime_num++;
		}
		cout << prime_num << endl;
		prime_num = 0;
	}
}

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

std::vector<int> PRIMES;

void init_primes(int max)
{
  if (max < 2) return;
  std::set<int> candidate;
  PRIMES.push_back(2);
  for (int i = 3; i < max; i+=2) {
    candidate.insert(i);
  }
  for (int i = 3; i < sqrt(max); i+=2) {
    std::set<int>::iterator it = candidate.find(i);
    if (it != candidate.end()) {
      PRIMES.push_back(i);
      int del_num = i;
      while (del_num < max) {
        it = candidate.find(del_num);
        if (it != candidate.end()) candidate.erase(it);
        del_num += i;
      }
    }
  }
  for (std::set<int>::iterator it = candidate.begin();
       it != candidate.end(); ++it) {
    PRIMES.push_back(*it);
  }
}

int main()
{
  const int max = 1000000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
}

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

bool isPrime(int x) {
    if (x==2) {
        return true;
    }
    if (x<2 || x%2==0) {
        return false;
    }
    i=3;
    while (i*i<=x) {
        if (x%i==0) {
            return false;
        }
        i+=2;
    }
    /*for (int i=3; i*i<=x; i+=2) {
     if (x%i==0) {
     return false;
     }
     }*/
    return true;
}
int main() {
    int n;
    int cnt;
    while (cin >> n) {
        cnt=0;
        for (int i=0; i<=n; i++) {
            if (isPrime(i)) {
                cnt++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main()
{
	int a = 0, b = 0;
	while (cin >> a)
	{
		b = 0;
		for (int i = 2; i <= a; i++)
		{
			int c = 0;
			for (int j = 2; j <= (i / 2); j++)
			{
				if (i % j == 0)
				{
					c = 1;
					break;
				}
			}
			if (c == 0)
			{
				b++;
			}
		}
		cout << b << endl;
	}

	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 <stdio.h>
#include <math.h>
#include <time.h>

int whether(int num);
int count(int num);

int main(){
	int n;
	int a;
	clock_t c, d;

	while(scanf("%d",&n) != EOF){
	scanf("%d",&n);
	a = count(n);
	printf("%d\n",a); 
}

	return 0;
}

int whether(int num){
	int s=sqrt(num);
	int i;
	for(i=3; i<=s; i+=2){ if(num%i==0) return 0; }

	return 1;
}

int count(int num){
	int a=1;
	int i;
	if(num <2){ return 0; }
	for(i=3; i<=num; i+=2){
		a += whether(i);
	}

	return a;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)

#ifdef ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif

#define pb emplace_back
#define lb lower_bound
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

#define ALL(c) (c).begin(),(c).end()

#define DBG0(x)    {if(DEBUG){ cout << #x << ": " << x << "\t"; }}
#define DBG(x)     {if(DEBUG){DBG0(x); cout << endl;}}
#define DBG2(x, y) {if(DEBUG){DBG0(x); DBG(y);}}
#define DBG3(x, y, z) {if(DEBUG){DBG0(x); DBG2(y, z);}}
#define DBG4(w, x, y, z) {if(DEBUG){DBG0(w); DBG3(x, y, z);}}

template <class T>
ostream& operator<<(ostream& os, vector<T> xs){ for(T x: xs) os << x << ' '; return os; }
template <class S, class T>
ostream& operator<<(ostream& os, pair<S,T> st){ os << "(" << st.first << "," << st.second <<")"; return os; }

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

const int PN = 2100000;
vint ps;
vector<bool> eratos;
void init_primes(void){
    eratos = vector<bool>(PN, false);
    ps.clear();
    for(int i = 2; i < PN; ++i){
        if(!eratos[i]){
            ps.pb(i);
            for(int j = i; j < PN; j += i)
                eratos[j] = true;
        }
    }
    return;
}
int main(void){
    init_primes();
    int n;
    while(cin >> n){
        if(n < 2){
            cout << 0 << endl;
            continue;
        }
        int l = 0, r = ps.size() - 1;
        while(r - l > 1){
            int med = (l + r) / 2;
            if(ps[med] <= n) l = med;
            else r = med;
        }
        cout << l + 1 << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int MAX_N = 1000000;

int main(){
    vector<bool> is_prime(MAX_N, true);
    vector<int> primes;
    for(int i=2;i<MAX_N;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j=i*i;j<MAX_N;j+=i){
                is_prime[j] = false;
            }
        }
    }

    int n;
    while(cin >> n){
        int ans = upper_bound(primes.begin(), primes.end(), n) - primes.begin();
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
	int n;
	int *prime,i,j;
	prime = new int[80000];
	int *answer = new int[MAX];
	int count;
	bool flag;

	count = 1;
	answer[1] = 0;
	answer[2] = 1;
	for(i = 3; i <= 1000000; i+=2){
		flag = true;
		for(j = 0; j < count; j++){
			if(i % prime[j] == 0){
				flag = false;
				break;
			}
			if(prime[j] * prime[j] > i) break;
		}
		if(flag == true){
			prime[count++] = i;
		}
		answer[i] = count;
		answer[i+1] = count;
	}
	while((cin >> n)!= NULL){
		cout << answer[n] << endl;
	}
	return 0;
}

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

//素数かどうか判定する関数
bool judge( int x )
{
    int count = 0;

    for( int i = 1; i <= x; i += 2 )
    {
        if( x % i == 0)
            count++;
    }

    if( count == 2 )
        return true;
    else
        return false;
}

int main()
{
    int n;

    while( cin >> n )                           //2が素数であることを予め考慮
    {
        int count = 1;                          //coutは素数の数なので、1

        if( n <= 1 )                            //nが1以下なら素数の数は0
        {
            count = 0;
        }

        for( int i = 3; i <= n; i += 2 )        //3以上の自然数について、奇数のみ素数判定を行う
        {
            if( judge(i) )
                count++;
        }

        cout << count << endl;
    }

    return 0;
}