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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

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

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
void printvec(vector<int> a){
    rep(i, a.size()-1){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[a.size()-1]);
}


vector<int> primes(100000);
int num_prime = 0; 

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

    double root_m = sqrt(m);

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

    return true;
}

void updatePrimes(int st, int max_v){
    for(int i=st;i < max_v+1; i+=2){
        if(IsPrime(i)){
            num_prime++;
            primes[num_prime] = i;
            // printf("%dは素数 ", i);
        }
    }
}
 
int main()
{
    primes[0] = 0;
    primes[1] = 2;
    primes[2] = 3;
    num_prime = 2;
    updatePrimes(5, 1000000);
    int num, id;

    while(scanf("%d", &num) != EOF){
        auto it = lower_bound(primes.begin(), primes.begin()+num_prime, num);
        if(*it > num) it--;
        id = it - primes.begin();
        printf("%d\n", id);
    }
    return 0;
}

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

#define MAX 1000000

int main(){
	bool p[MAX+1];
	int num,answer;

	while( scanf("%d" , &num) != EOF ){	
		// ツ陛渉青板づ個渉可甘コツ可サ
		p[0] = false;
		p[1] = false;
		for(int i=2 ; i<=MAX ; i++){
			p[i] = true;
		}
		answer = 0;

		//ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「
		for(int i=2 ; i<=sqrt(MAX)+1 ; i++){
			if(p[i]==1){
				for(int j=i*2; j<=MAX; j=j+i){
					p[j] = false;
				}
			}
		}

		// Output
		for(int i=0; i<=num; i++){
			if(p[i]){
				answer++;
			}
		}
		printf("%d\n", answer);
	}
}

C++: #include<cstdio>
#include<cstring>
int main(){
	int a,b,d;
	while(~scanf("%d",&a)){
		int c[a+1];
		memset(c,0,sizeof(c));
		d=0;
		for(b=2;b<=a;b++){
			if(c[b]==0){
				d++;
				for(int i=b;i<a+1;i+=b)	c[i]=1;
			}
		}
		printf("%d\n",d);
	}
}

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

using namespace std;

int furui(int N){
  int i;
  int count=0;
  int array[1000000];
  array[0]=false;
  array[1]=false;
    
  for(i=2;i<=N;i++){
    array[i]=true;
  }

  for(i=2;i<=N;i++){
    if(array[i]==true)for(int j=i*i;j<=N;j+=i){
	array[j]=false;
      }
  }

  for(i=2;i<=N;i++){
    if(array[i]==true)count++;
  }

  return count;
}

int main(){
  int cnt=0,n;
  while(cnt<30){
    cnt++;
    cin >> n;
    cout << furui(n) <<endl;
}

  return 0;
}

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)){
		if(n == 'EOF') break;
		cout << sieve(n) << '\n';
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

bool a[1000000];

int main()
{
    memset(a, true, sizeof(a));

    int n;
    while (~scanf("%d", &n)) {
        for (int i = 2; i * i <= n; ++i) {
            if (!a[i]) continue;
            for (int j = i + i; j <= n; j += i) a[j] = false;
        }
        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += a[i];
        printf("%d\n", cnt);
    }
}

C++: #include <stdio.h>

int main(int argc, const char * argv[])
{
    int i, j, k, n, count;
    int a[999999];
    
    count = 0;
    
    while(scanf("%d",&n) != EOF){
        if (count == 0) {
            if (n > 1) {
                a[count++] = 2;
                if (n > 2) {
                    a[count++] = 3;
                    for(i=5; i<=n; i+=2){
                        k=0;
                        for(j=0; a[j]*a[j] <= i; j++){
                            if(i%a[j] == 0) {
                                k = 1;
                                break;
                            }
                        }
                        if (k == 0) {
                            a[count++] = i;
                        }
                    }
                }
            }
            printf("%d\n",count);
        } else {
            if (n <= a[count - 1]) {
                for (i=count - 1; n < a[i]; i--);
                printf("%d\n", i+1);
            } else {
                if (a[count-1] == 2) {
                    a[count++] = 3;
                    printf("%d\n",count);
                } else {
                    for(i=a[count - 1]+2; i<=n; i+=2){
                        k=0;
                        for(j=0; a[j]*a[j] <= i; j++){
                            if(i%a[j] == 0) {
                                k = 1;
                                break;
                            }
                        }
                        if (k == 0) {
                            a[count++] = i;
                        }
                    }
                    printf("%d\n", count);
                }
            }
        }
    }
    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{
	for(int j=3; j < i/2; j++){
	  if(i%j == 0 ) flag = 0;
	}
      }
      if(flag == 1) sum++;
      flag = 1;
    }
    cout << sum <<endl;
    sum = 0;
  }
}

C++: #include <stdio.h>
int main(){
    int mem[ 50000 ] = { 2,3,5,7,11 };
    int i,m = 5,x;
    for( i = 12;i < 100000;i++ ){
        if( i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0 && i % 11 != 0 ) mem[ m++ ] = i;
    }
    while( 1 ){
        if( feof( stdin ) != 0 ) break;
        scanf( "%d",&x );
        for( i = 0;mem[i] <= x;i++ );
        printf( "%d\n",i );
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int prime[1000000];
int main(){
    int n,ans=0;
    for(int i=0;i<1000000;i++)
        prime[i]=1;
    prime[1]=0;
    prime[2]=1;
    for(int i=1;i<1001;i++){
        if(prime[i]==1){
            for(int j=i+1;j<1000000;j++){
                if(j%i==0)
                    prime[j]=0;
            }
        }
    }
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        if(prime[i]==1)
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}