Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// エラストテネスの篩, o(n)程度
// n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか
int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr){
	bool flag0 = false, flag1 = false;
	if(prime == nullptr){
		flag0 = true; prime = new int[n];
	}
	if(is_prime == nullptr){
		flag1 = true; is_prime = new bool[n + 1];
	}

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

	if(flag0) delete prime;
	if(flag1) delete is_prime;

	return p;
}


int main(void){
	int n;
	while(scanf("%d", &n)){
		cout << sieve(n) << '\n';
	}

	return 0;
}

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

using namespace std;

int A[100];
int Pream(int n)
{
	int kusa = (int)sqrt((double)n);
	int mama = 0;

	for (int i = 0; i < n; i++)
		A[i] = 1;  // ??¨????????°???1????????????
	A[0] = 0;    // 1????´???°??§?????????

	for (int i = 1; i < kusa; i++) {
		if (A[i] == 1)   // prime[i]????´???°??????
		{
			for (int j = (i + 1); (i + 1) * j <= n; j++)
				A[(i + 1) * j - 1] = 0;  // ?´???°????????°????´???°??§?????????
		}
	}
	for (int i = 0; i < n; i++)
		if (A[i] == 1)  // 1????????£???????????????????´???°
			mama++;

	return mama;
}

int main()
{
	int n;
	cin >> n;
	while (n != -1)
	{
		cout << Pream(n) << endl;
		cin >> n;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector <int> wow(100001);

bool prime(int m){
	if(m < 2)return false;
	if(m == 2)return true;
	if(m%2 == 0)return false;

	for(int i = 3; i*i <= m; i += 2){
		if(m%i == 0)return false;
	}
		return true;
}

int main(){
	int n;
	
	while(cin >> n){
		int a=0;
		for(int i = 1; i <= n; ++i){
			if(wow[i] == 0){
				if(prime(i)){
					++a;
					wow[i] = 1;
				}else{
					wow[i] = 2;
				}
			}else if(wow[i] == 1){
				++a;
			}
	}
		cout << a << '\n';
	}
}

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

int ans ;
int N ;
bool prime[1000200] ;

void SE ( ) ;

int main ( ) 
{
	memset ( prime , false , sizeof ( prime ) ) ;
	SE ( ) ;
	while ( scanf ( "%d" , &N ) == 1 ) {
		ans = 0 ;
		if ( N > 2 ) {
			ans++ ;
		}
		for ( int i = 3 ; i < N ; i += 2 ) {
			if ( prime[i] == false ) {
				ans++ ;
			}
		}
		printf ( "%d\n" , ans ) ;
	}
	return 0 ;
}

void SE ( )
{
	prime[0] = prime[1] = true ;
	for ( int i = 3 ; i < 1004 ; i += 2 ) {
		if ( prime[i] == false ) {
			for ( int j = i * i ; j < 1000200 ; j += i * 2 ) {
				prime[j] = true ;
			}
		}
	}
}

C++: #include <iostream>
#include <cmath>
using namespace std;
void cprime(int, int&);

int main() {
	int n;
	
	while (cin >> n) {
		int count = 0;
		for (int i = 0; i < n;i++) {
			cprime(i + 1,count);
		}
		cout << count << endl;
	}
}

void cprime(int n, int& count) {
	if (n == 1) return;
	for (int i = 2; i <= sqrt(n);i++) {
		if (n % i == 0) return;
	}
	count++;

	return;
}

C++: #include <iostream>

#define N 1000000

using namespace std;

int main() {
	int num=0,y=0, n;
	while(cin>>n){
		num = 0;
		for(int i=2; i<=n; i++){
			y = 0;
			for(int j=2; j<i; j++){
				if(i%j==0){ y++;}
			}
			if(y==0){ num++; }
		}
		cout<<num<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

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

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<1000;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 <bits/stdc++.h>
using namespace std;

vector<int> eratosthenes(int n) {
  vector<int> res, p(n + 1, 1);
  p[0] = p[1] = 0;
  for (int i = 2; i * i <= n; ++i) {
    if (p[i]) {
      for (int j = 2 * i; j <= n; j += i) {
        p[j] = 0;
      }
    }
  }
  for (int i = 0; i <= n; ++i) {
    if (p[i]) res.push_back(i);
  }
  return res;
}

int main() {
  int n;
  while (cin >> n) cout << eratosthenes(n).size() << endl;
}

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++;
}
cout<<ans<<endl;}}

C++: #include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;


int main(){
	int n = 0;
	int count;
	bool flag = false;
	while(cin >> n){
		count = 1;
		for(int i = 1; i <= n; i += 2){
			if(i < 2);
			else{
				for(int j = 3; j * j <= i; j += 2){
					if(i % j == 0){
						flag = true;
						break;
					}
				}
				if(flag != true){
					count++;
				}
				flag = false;
			}
		}
		cout << count << endl;

	}

	return 0;
}

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

using namespace std;

int main() {
  const int N_MAX = 999999;
  const double MAX = sqrt(N_MAX);

  vector<int> preprime_list, prime_list;

  for (int i = 2; i <= N_MAX; i++) {
    preprime_list.push_back(i);
  }

  while (preprime_list[0] < MAX) {
    for (int i = 1; i < preprime_list.size(); i++) {
      if (preprime_list[i]%preprime_list[0] == 0)
        preprime_list.erase(preprime_list.begin()+i);
    }
    prime_list.push_back(preprime_list[0]);
    preprime_list.erase(preprime_list.begin()+0);
  }
  return 0;
  prime_list.insert(prime_list.end(), preprime_list.begin(), preprime_list.end());

  int data,count;
  while (cin >> data) {
    for (int i = 0; i < prime_list.size() && prime_list[i] <= data; i++, count = i);
    cout << count << endl;
  }
}

C++: #include<iostream>
#include<math.h>
main(){
	int i,j,n,p[1000000];
	std::cin>>n;
	for(i=2;i<=n;i++)
		p[i]=1;
	for(i=2;i<n;i++)
		if(p[i])
			for(j=2;i*j<=n;j++)
				p[i*j]=0;
	j=0;
	for(i=2;i<n;i++)
		j+=p[i];
	std::cout<<j<<std::endl;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN = 1000000;
bool isPrime[MAXN];
int main(){
  fill(isPrime,isPrime+MAXN,true);
  isPrime[0] = isPrime[1] = false;
  isPrime[2] = true;
  for(int i = 0;i < MAXN;i++){
    if(isPrime[i]){
      for(int j = i*2;j < MAXN;j+=i){
        isPrime[j] = false;
      }
    }
  }
  vector<int> primes;
  for(int i = 0;i < MAXN;i++){
    if(isPrime[i])primes.push_back(i);
  }
  int n;

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