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>
using namespace std;
#define MAX 1000000
#define SQRTMAX 1000
void seive_prime(bool seive[])
{
	for(int i=2;i<=SQRTMAX;i++) {
		if(seive[i] == false) {
			for(int j=i*2;j<=MAX;j+=i) {
				seive[j]=true;
			}
		}
	}
}
int main() {
	int n;
	bool sieve[MAX+1] = {false};
	// エラトステネスの篩
	seive_prime(sieve);
	
	while(cin >> n) {
		int cnt = 0;
		for(int i=2;i<=n;i++) {
			if(sieve[i] == false)
				cnt++;
		}
		cout << cnt << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int main(){
  bool prime[1000000] = {};
  int sum[1000000]; sum[0] = sum[1] = 0; sum[2] = 1;
  for(int i = 3 ; i < 1000000 ; i += 2 ){
    sum[i] = sum[i + 1] = sum[i - 1];
    if(!prime[i]){
      for(int j = i + i + i ; j < 1000000 ; j += i + i ){
        prime[j] = true;
      }
      sum[i]++;
      sum[i+1]++;
    }
  }
 
  int n;
  while(cin >> n){
    cout << sum[n] << endl;
  }
}

C++: #include <iostream>
#include <cstring>
using namespace std;
#define maxn 1000000

int  isprime(int n)
{
  
  bool prime[maxn];
  int p = 0;
  memset(prime,true,sizeof(prime));
  prime[0] = prime[1] = false;
  for(int i=2;i<=n;i++)
  {
    if(prime[i])
    {
      for(int j=2*i;j<=n;j+=i) prime[j] = false;
      p++;
    }
  }

  return p;
}

int main()
{

    int n;
    while(cin>>n)
    {
      cout<<isprime(n)<<endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
bool ifprime(int i);
int numbers[31];
int nn[31];
int num = 0;
int main()
{
	int n, count;
	bool ans;
	while ((scanf("%d", &n)) != EOF)
	{
		if (num > 0)
		{
			for (int i = 0; i <= num; i++)
			{
				if (n == numbers[i])
				{
					printf("%d\n", nn[i]);
					break;
				}
			}
		}
		else
		{
			count = 0;
			for (int i = 2; i <= n; i++)
			{
				ans = ifprime(i);
				if (ans == true)
				{
					++count;
				}
			}
			printf("%d\n", count);
			numbers[num] = n;
			nn[num] = count;
			num++;
		}
	}

	return 0;
}
bool ifprime(int i)
{
	int m = (int)sqrt(i);
	for (int j = 2; j <= m; j++)
	{
		if (i% j == 0)
		{
			return false;
		}
	}
	return true;
}

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

static bool sieve[1000010];
static int primecount[1000010];

int main() {
	fill(sieve, sieve+1000010, true);
	sieve[0]=sieve[1]=false;
	primecount[0]=primecount[1]=0;
	int partial_count = 0;
	for(int i = 2; i < 1000010; i++) {
		primecount[i] = partial_count;
		if(!sieve[i])continue;
		primecount[i] = ++partial_count;
		if(i<10000)
			for(int j = i*i; j < 1000010; j+=i) {
				sieve[j]=false;
			}
	}
	while(true) {
		int n; if(scanf("%d", &n)<1)break;
		printf("%d\n", primecount[n]);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int prime[80000];
    int ptr=2;
    prime[0] = 2;
    prime[1] = 3;
    for(int num=5; num<1000000; num+=2){
        bool f = false;
        for(int i = 0; i<ptr; i++){
            if (prime[i]*prime[i] > num) break;
            if (num%prime[i]==0) {
                f = true;
                break;
            }
        }
        if(!f) prime[ptr++] = num;
    }
    prime[ptr]=1000001;
    int n;
    while(cin >> n){
        int k=0;
        for(;prime[k]<=n;k++);
        cout << k << endl;
    }
     
    return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#define MAX_NUM 999999
int numbers[MAX_NUM] = {-1, -1};
int isPrime(int num) {
    int i;
    if(numbers[num]) {
        return 0;
    }
    for(i=num << 1; i<=MAX_NUM; i+=num) {
        numbers[i] = -1;
    }
    return 1;
}

int main() {
    int i, n, count;
    while(scanf("%d", &n) != EOF){
        count = 0;
        for(i=2; i<=n; ++i) {
            count += isPrime(i);
        }
        printf("%d\n", count);
    }
    return 0;
}

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

int main(void){
  int n;
  bool p[1000000];
  p[0] = p[1] = 0;
  p[2] = 1;
  int ans = 0;
  bool flag;
  for(int i = 0; i < 1000000; i++)
    p[i] = false;
  p[2] = true;
  for(int i = 3; i <= 1000000; i += 2){
    flag = true;
    for(int j = 3; j * j <= i; j += 2){
      if(i % j == 0){
	flag = false;
	break;
      }
    }
    if(flag)
      p[i] = true;
  }
  // cout << "end" << endl;
  while(cin >> n){
    int ans = 0;
    for(int i = 2; i < n; i++){
      if(p[i])
	ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    int maxy = (int)sqrt(100000);
    int prime[100000];
    for(int i = 0; i < 100000; i++){
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for(int i = 2; i <= maxy; i++){
        if(prime[i] == 1){
            for(int j=i*2; j <= maxy; j+=i){
                prime[j] = 0;
            }        
        }
    }
    int n;
    while(cin >> n){
        int ans = 0;
        for(int i=0; i <= n; i++){
            if(prime[i] == 1){
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
  int n,flag=1,sum = 0;

  while(cin >> n){

    for(int i=2; i <= n; i++){
      if(i != 2 && i%2 == 0) flag = 0;
      else if(i != 3 && i%3 == 0) flag = 0;
      else if(i != 5 && i%5 == 0) flag = 0;
      else{
	for(int j=3; j < i/2; j+2){
	  if(i%j == 0 ) flag = 0;
	}
      }
      if(flag == 1) sum++;
      flag = 1;
    }
    cout << sum <<endl;
    sum = 0;
  }
}

C++: #include <stdio.h>

const int MAX_V = 100000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

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

int main(){
    init();
    int num;
    while(scanf("%d", &num) != EOF){
        int count=0;
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}