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>
#include <cstring>
using namespace std;
const int SIZE = 1000000;
bool mark[SIZE];
long long int num[SIZE];
void findp(){
    memset(mark, true, sizeof(mark));
    for(int i = 2; i <= sqrt(SIZE); i ++){
        if(mark[i]){
            for(int j = i + i; j < SIZE; j += i){
                mark[j] = false;
            }
        }
    }
    num[1] = 0;
    for(int i = 2; i < SIZE; i ++){
        num[i] = num[i-1];
        if(mark[i]){
            num[i] += 1;
        }
    }
}
int main(){
    int n;
    findp();
    while(cin>>n){
        printf("%ld\n", num[n]);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
bool isprime[1000005];
int prime[1000005];
void sieve() {
	for (int i = 0; i <= 1000000; i++) isprime[i] = true;
	isprime[0] = isprime[1] = false;
	prime[0] = prime[1] = 0;
	for (int i = 2; i <= 1000000; i++) {
		if (isprime[i]) {
			prime[i] = prime[i - 1] + 1;
			for (int j = 2 * i; j <= 1000000; j += i) isprime[j] = false;
		}
		else prime[i] = prime[i - 1];
	}
}
int main() {
	sieve();
	int n;
	while (cin >> n) {
		cout << prime[n] << endl;
	}
}

C++: #include <stdio.h>
#include <iostream>
 
using namespace std;
 
void uru(int c, int d) {
    int counter = 0;
 
    for (int i = c; i <= d; i++) {
        if (i % 4 == 0) {
            if (i % 100 == 0) {
                if (i % 400 == 0) {
                    cout << i << endl;
                    counter++;
                } 
            } else {
                cout << i << endl;
                counter++;
            }
        }
    }
    if (counter == 0) {
        cout << "NA" << endl;
    }
    //cout << endl;
    return;
}
 
int main() {
    int a,b;
 	bool flag=false;
    while (cin >> a >> b) {
    	if (a == 0 && b == 0) {
            break;
        }
    	if(flag) cout<<endl;
            uru(a,b);
    	flag=true;
    }
	//cout<<000000<<endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(void){
  const int n = 1000000;
  bool* check_A = (bool*)malloc(sizeof(bool)*n);
  int*  num_A   = (int*)malloc(sizeof(int)*n);
  int N = 0, temp = 2;
  memset(check_A, true, n);
  check_A[0] = false;
  check_A[1] = false;
  num_A[0] = 0;
  num_A[1] = 0;
  for(int i = 0; i < n; i++){
    if(check_A[i]){
      for(;temp < i;temp++){
	num_A[temp] = N;
      }
      temp++;
      num_A[i] = ++N;
      for(int j = 2; i*j < n; j++){
	check_A[i*j] = false;
      }
    }
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define N_MAX 1000

using namespace std;

int main(){
	
	int array[N_MAX],i,j,n, num = 0;
	
	while(cin>>n){
		num = 0;
		for (i=0;i<n;i++)
			array[i]=i+2;
		for (i=0;i<n;i++){
			for (j = (i+2); (i+2) * j <= n; j++)
				array[(i+2) * j - 2] = -1;}

	for (i = 0; i < n-1; i++){
    if (array[i] != -1)
	num++;
	}
	cout<<num<<endl;
	}
	cin>>n;
  
	return (0);
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

#define MAX 1000000

static bool gosei[MAX];

void b(){
	for(int i=2;gosei[i]==false&&i<MAX;i++)
		for(int j=2,k;(k=i*j)<MAX;j++)
			gosei[k]=true;
}

int c(int n){
	int cnt=0;
	for(int i=2;i<=n;i++)
		if(!(gosei[i]))cnt++;
	return cnt;
}

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

C++: #include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
 _Bool *list;
 int n,i,j,cnt;
 
 while(scanf("%d",&n) != EOF)
 {
  cnt = 0;
  list = (int*)calloc(n+1,sizeof(int));
  for(i = 2; i <= n; i++)
  {
   if(list[i] != 1) /*prime number:0 no prime numbers:1*/
   { 
    cnt++;
    for(j = i+i; j <= n; j+=i) list[j] = 1;
   }
  }
  printf("%d\n",cnt);
  free(list);
 } 
 return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#define LIMIT 1000000

int main(){
	int num;
	while( scanf("%d",&num)!=EOF ){
		bool sosu[LIMIT]={0};
		int now=2,count=0;
		while(now<=num){
			if(!sosu[now]){
				count++;
				for(int i=now;i<LIMIT;i+=now){
					sosu[i] = true;
				}
			}
			now++;
		}
		std::cout << count << std::endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define MAX (100000)

int main(void)
{
	int prime[MAX + 1] = {1};
	int n;
	int ans;
	int i;
	char str[100];
	
	for (int i = 0; i <= MAX; i++){
		prime[i] = 1;
	}
	
	prime[0] = prime[1] = 0;
	i = 0;
	while (i * i <= MAX){
		while (prime[++i] != 1 && i * i <= MAX);
		//printf("%d ", i);
		for (int j = 2; j * i <= MAX; j++){
			//printf("%d\n", i * j);
			prime[i * j] = 0;
		}
	}
	
	while (fgets(str, 100, stdin)){
		sscanf(str, "%d", &n);
		
		ans = 0;
		for (int i = 2; i <= n; i++){
			if (prime[i] == 1){
				ans++;
			}
		}
	
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: #include <iostream>
#include <cmath>
//#include <ctime>
#define Even(n) n%2
using namespace std;

void count_Prime(int n);
bool IsPrime(int num);


int main()
{
	int Data = 0;
//	clock_t start, end;
	while (cin >> Data)
	{
//		start = clock();
		count_Prime(Data);
//		end = clock();

		cout << (double)(end - start) / CLOCKS_PER_SEC << "sec" << endl;
	}

	return 0;
}

void count_Prime(int n)
{
	int counter = 0,  i = 0;
	for (i = 2; i <= n; ++i)
	{
		if (IsPrime(i))
			counter++;
	}

	cout << counter << endl;

}

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

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

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

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

int main() {
	int array[1000000];
	int n, count = 0;
	for(int i = 0; i < 1000000; i++) {
		array[i] = 1;
	}
	array[0] = 0;
	array[1] = 0;
	for(int i = 2; i < 1000000; i++) {
		if(array[i] != 0) {
			for(int j = i * 2; j < 1000000; j += i) {
				array[j] = 0;
			}
		}
	}
	while(cin >> n) {
		for(int i = 0; i <= n; i++) {
			count += array[i];
		}
		cout << count << endl;
		count = 0;
	}

	return 0;
}

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

const int MAX_N = 999999;
bool prime[MAX_N + 1];

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

int is_prime(int n)
{
  return prime[n];
}

int main()
{
  int n, i;
  int ans = 0;
  sieve();
  while(cin >> n){
    for(i = 0; i < n; i++){
      if(is_prime(i)){
	ans++;
      }
    }
    if(i == n){
      break;
    }
  }
  printf("%d\n", ans);
}