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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

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

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

int CountPrime(int N);
int CheckPrime(int N);
bool IsPrime(int num);

int main()
{
	int N;

	while (std::cin >> N)
	{
		std::cout << CountPrime(N) << std::endl;
	}
}

int CountPrime(int N)
{
	int Counter = 0;

	for (int i = 1; i <= N; ++i)
	{
		Counter = Counter + CheckPrime(i);
	}

	return Counter;
}

int CheckPrime(int N)
{
	if (!IsPrime(N))
		return 0;

	return 1;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????


	double sqrtNum = std::sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

C++: #include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>


/*
	HOME-  Volume0-0009
	Submit Statistics
	 
	PCK 2003
	Prime Number
	Time Limit : 1 sec, Memory Limit : 32768 KB
	English version is here
	Prime Number

	6 ÈºÌ³Ì® n ðüÍµAn ÈºÌfª¢­Â é©ðoÍ·évOðì¬µÄº³¢B½¾µAfÆÍ 1 Æ©ª©gÅµ©èØêÈ¢³Ì®Ì¤¿ 1 ðÌ¼¢½àÌð¢¢Ü·Bá¦Î 10 ÈºÌfÍA2, 3, 5, 7 Å·B
	Input

	¡Ìf[^Zbgª^¦çêÜ·Bef[^ZbgÉ n ªPsÉ^¦çêÜ·BüÍÌÅãÜÅµÄº³¢B
	Output

	ef[^Zbg²ÆÉAn ÈºÌfÌÂðPsÉoÍµÄº³¢B
	Sample Input

	10

	Output for the Sample Input

	4

*/

using namespace std;


int main()
{
	string s;
	
	while (getline(cin, s))
	{
		int n;
		sscanf(s.c_str(), "%ld", &n);
		
		vector<int> v;
		v.reserve(n);
		
		for (int i = 0; i <= n; i++)
		{
			v.push_back(1);
		}
		v[0] = 0;
		v[1] = 0;
		
		for (int i = 2; i <= n; i++)
		{
			if (0 == v[i])
			{
				continue;
			}
			for (int k = i * 2; k <= n; k++)
			{
				if (0 == (k % i))
				{
					v[k] = 0;
				}
			}
		}
		
		int x = 0;
		for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
		{
			if (*it)
			{
				x++;
			}
		}
		
		printf("%d\n", x);
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
const int MAX=1000000;
bool t[MAX+1];
int c[MAX+1];

void make_table(){
	t[0]=t[1]=1;
  for(int i=0;i<=MAX;i++){
 	if(!t[i]){
 		for(int j=i+i;j<=MAX;j+=i)
 			t[j]=1;
 	}
  }
}
int main(){
  make_table();
  	int n; 
	for(int i=1;i<=MAX;i++){
		c[i]=(t[i])?c[i-1]:c[i-1]+1;
	}

	while(cin>>n)
		cout<<c[n]<<endl;
	
}

C++: #include<iostream>

int main(){

	bool data[100001];

	for (int i = 0; i < 100001; i++)
		if (i % 2 == 0)
			data[i] = false;
		else
			data[i] = true;

	int in;

	int res=0;

	for(int i=2;i<=100000;i++){
		if (i % 2 != 0) {
			for (int j = 2; j < i; j++) {
				if (i%j == 0) {
					data[i] = false;
					goto fl;
				}
			}
		}
	fl:;
	}

	while (true) {

		std::cin >> in;

		for (int i = 2; i <= in; i++) {
			if (data[i] == true)
				res++;
		}

		std::cout << res << std::endl;

	}

		return 0;
}

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

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 0;
		if (cin.eof())
			return 0;
		for (int i = 2; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

bool isPrime(int x) {
	if (x % 2 == 0)
		return true;
	for (int j = 3; j * j <= x; j += 2) {
		if (x % j == 0)
			return false;
	}
	return true;
}

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

int prime_num(int n)
{
  ++n;
  bool* array = new bool[n];
  fill_n(array, n, true);
  array[0] = array[1] = false;

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

  int result = 0;
  for (int i = 0; i < n; ++i)
  {
    if (array[i]) ++result;
  }

  delete[] array;
  return result;
}

int main(void)
{
  int n;
  while (cin >> n)
  {
    cout << prime_num(n) << endl;
  }
  return 0;
}

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

int main(){
	int num;
	int count = 0;
	int i,j;

	cout << "数字を入力してください" << endl << "number :";
	cin >> num;

	for(i=2; i<num; i++){
		for(j=2; j<i; j++){
			if(i%j ==0){
				break;
			}
		}
		if(j == i){
			count++;
		}
	}
	cout << count << endl;
	cin >> num;
	return 0;
}

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

int main(){
  int a;
  int i, j;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=a^0.5;
      for(i=2; i<=a_sqrt; i++){
        for(j=past+1; j<=a; j++){
          if(j%i==0) chk[j]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

C++: #include <cstdio>
#include <cstring>
const int MAX_n = 999999;
bool isPrime[MAX_n+1];
int sum[MAX_n+1];
int main()
{
    memset(isPrime,true,sizeof(isPrime));
    for(int i = 2; 2*i <= MAX_n ; ++i)
        if(isPrime[i])
            for(int j = 2*i; j <= MAX_n; j+=i)
                isPrime[j] = false;
    isPrime[0] = isPrime[1] = false;
    
    for(int i = 0; i < MAX_n; ++i)
        sum[i+1] = sum[i] + isPrime[i+1];
    
    int n;
    while(scanf("%d",&n) != EOF)
    {
        int ans = sum[n];
        printf("%d\n",ans);
    }
    
}

C++: #include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=1000001;
bool p[MAXN];
vector<int> a;
int main(){
	memset(p,false,sizeof(p));
	for (int i=2;i<sqrt(MAXN);i++)
		for (int j=i+i;j<MAXN;j+=i)
			p[j]=true;
	for (int i=2;i<MAXN;i++)
		if (!p[i])
			a.push_back(i);
	int n;
	while (cin >> n){
		vector<int>::iterator f=lower_bound(a.begin(),a.end(),n);
		if (*f==n)
			cout << f-a.begin()+1 << endl;
		else
			cout << f-a.begin() << endl;
	}
	return 0;
}

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


using namespace std;

int main() {
	vector<int> prime_num{ 2, 3 };
	int n;

	while (cin >> n){
		int result;
		if (n <= 1) {
			result = 0;
		}
		else if (n == 2){
			result = 1;
		}
		else if (n < prime_num.back()){
			result = count_if(prime_num.begin(), prime_num.end(), [n](int a){return a <= n; });
		}
		else {
			for (int i = prime_num.back() + 2; i <= n; i += 2) {
				if (all_of(prime_num.begin(), prime_num.end(), [i](int a){return (i % a) != 0; })) {
					prime_num.push_back(i);
				}
			}
			result = prime_num.size();
		}


		cout << result << endl;javascript:void(0)
	}


	return 0;
}