Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

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

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

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

int main(){
  int MAX = 1000000;
  int n;
  int cnt=0;
  vector<bool> num(n);
  
  for(int i=0; i<MAX; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;

  for(int i=2; i<=sqrt(MAX); i++){
    if(num[i]){
      for(int j=i*2; j<MAX; j+=i){
	num[j] = false;
      }
    }
  }

  while(cin >> n){
    cnt = 0;
    for(int i=0; i<=n; i++){
      if(num[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

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

const int limit = 1000000;
bool prime[limit + 10];

void era() {
    for(int i = 0; i < limit; i++) prime[i] = true;
    prime[0] = prime[1] = false;
    for(int i = 2; i * i <= limit; i++) {
        if(prime[i]) {
            for(int j = 2 * i; j < limit; j += i) {
                prime[j] = false;
            }
        }
    }
}

int main() {
    era();
    int n;

    while(cin >> n) {
        int ans = 0;

        for(int i = 0; i <= n; i++) {
            if(prime[i]) ans++;
        }
        cout << ans << endl;
    }
}

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

bool w[1000000];
int a[1000000];

int main()
{
	for(int i = 0; i < 1000000; i++)
	{
		w[i] = true;
	}
	int all = 0;
	a[0] = 0;
	a[1] = 0;
	for(int i = 2; i < 1000000; i++)
	{
		if(w[i])
		{
			all++;
			for(int j = 2; i * j < 1000000; j++)
			{
				w[i * j] = false;
			}
		}
		a[i] = all;
	}
	while(1)
	{
		int n;
		if(EOF == scanf("%d",&n))
		{
			break;
		}
		printf("%d\n",a[n]);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
int vis[1000000];
int prime[10000];
int k=0;
void deal()
{
   memset(vis,0,sizeof(vis));
   for(int i=2;i*i<=999999;i++)
   {
      if(!vis[i])
      {
         prime[k++]=i;
         for(int j=i*i;j<=999999;j+=i)
         {
            vis[j]=1;
         }
      }
   }
}
int main()
{
   deal();
   int n;
   while(scanf("%d",&n)==1)
   {
      int sum=0;
      for(int i=0;i<k;i++)
      {
         if(prime[i]<=n)
            sum++;
         else break;
      }
      cout<<sum<<endl;
   }
   return 0;
}

C++: #include<iostream>

using namespace std;

int prime[1000000];
bool is_prime[1000000];


int sieve(int n){

  int p=0;
  for(int i =0;i<=n;i++)is_prime[i] = 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;

}


main(){
  
  int n;

  while(cin >> n){
    
    cout << sieve(n) << endl;
    

  }


  return 0;
}

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

using namespace std;

int main() {

	int n,count;

	while (cin >> n) {
		count = 0;
		
		//?´???°????????????????¨???¶?????????????????????????¢????
		bool *is_prime;
		is_prime = (bool *)malloc(n+1);
		if (is_prime == NULL) {
			cout << "malloc error" << endl;
			break;
		}

		//????????¨????´???°??§????????¨??????
		for (int i = 0; i <= n; i++) {
			is_prime[i] = true;
		}

		for (int i = 2; i <= n; i++) {
			//?´???°???????????§????????£???????????????????????§??????
			if (is_prime[i] == true) {
				//????????°???????????§????????°????????£?????????
				for (int j = i+1; j <= n; j++) {
					//cout << "i=" << i << " j=" << j << " is_prime(i)=" << is_prime[i] << " is_prime(j)=" << is_prime[j] << endl;
					if (is_prime[j] == true) {
						if (j%i == 0) {
							//????????????????????????????´???°??§?????????
							is_prime[j] = false;
						}
					}
				}
			}
		}

		//?´???°??¨?¢????????????°????????°????????????
		for (int i = 2; i <= n; i++) {
			if (is_prime[i] == true) {
				count++;
				//cout << " " << i;
			}
		}

		//??¨???
		cout << count << endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

bool isprime[1000000];

int main(int argc, char **argv){
	int n;
	int cnt;
	int checkcnt = 0;
	for (int i = 0; i < 1000000; i++) {
		isprime[i] = true;
	}
	while (cin >> n && checkcnt < 30) {
		cnt = 0;
		int i;
		for (i = 2; i <= sqrt(n); i++) {
			if (isprime[i]) {
				for (int j = 2; j <= n / i; j++) {
					isprime[i * j] = false;
				}
			}
		}
		for (int k = 2; k <= n; k++) {
			if (isprime[k]) {
				cnt++;
			}
		}
		cout << cnt << endl;
		checkcnt++;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int prime[1000005],e;
bool is_prime[1000005];
int presum[1000005];
void solve()
{
    prime[0]=prime[1]=1;
    for(int i=2;i<=1000000;i++)
    {
        if(!is_prime[i])
        {
            prime[++e]=i;
            if((long long)i*i>1000000) continue;
            for(int j=i*i;j<=1000000;j+=i) is_prime[j]=1;
        }
    }
}
void pre()
{
    presum[0] =presum[1]= 0;
    for(int i = 2; i <=1000000; i++)
        presum[i] = is_prime[i] ? presum[i - 1]: presum[i - 1]+1;
}
int main()
{
    int n;
    solve();
    pre();
    //cout<<e;
    while(cin>>n)
    {
       cout<<presum[n]<<endl;
    }

   return 0;
}

C++: #include<iostream>
using namespace std;
bool prime(int n){
	for(int i=2;i<n;i++){
		if(n%i==0)return false;
	}
	return true;
}
int main(){
	int a;
	while(cin>>a){
	int sum=0;
	for(int j=2;j<a;j++){
		if(prime(j))sum++;
	}
	cout<<sum<<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];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		result[cnt] = 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:素数の個数
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;

const int maxn=1e6+5;

int isprime[maxn];

int solve(int n)
{
    int p=0;
    for(int i=2;i<=n;i++){
        if(!isprime[i]){
            p++;
        }
        for(int j=2*i;j<=n;j+=i){
            isprime[j]=1;
        }
    }
    return p;
}

int main()
{
    int n;
    while(~scanf("%d",&n)){
        cout<<solve(n)<<endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(){
    int t;
    while(cin >> t){
        cerr << t << endl;
    }
}