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 <iostream>
#include <vector>
using namespace std;
int main( void )
{
	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		if ( n <= 1 )
			cout << "0" << endl;
		
		vector <bool> p(n+1, true);

		p[0] = p[1] = false;
		for ( int i = 4; i <= n; i += 2 )
		{
			p[i] = false;
		}

		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
			{
				for ( int j = i+i; j <= n; j += i )
				{
					p[j] = false;
				}
			}
		}

		int kotae = 1;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( p[i] )
				kotae++;
		}

		cout << kotae << endl;
	}

	return 0;
}

C++:  #include<iostream>
 using namespace std;
 
 int main()
 {
 	int N;
 	while(cin>>N)
 	{
 		int count=0;
 		for(int i=2;i<=N;i++)
 		{
 			bool isPrime=true;
 			for(int j=2;j*j<=i;j++)
 			{
 				if(i%j==0)
 				{
 					isPrime=false;
 					break;
 				}
 			}
 			if(isPrime) 
 			{
 				count++;
 			}
 		}
 		cout<<count<<endl;
 	}
 	return 0;
 }

C++: #include<iostream>
#include<math.h>
main(){int i,j,n,p[1000000];std::cin>>n;for(i=2;i<=n;i++)p[i]=1;for(i=2;i<n;i++)if(p[i])for(j=2;i*j<=n;j++)p[i*j]=0;j=0;for(i=2;i<=n;i++)j+=p[i];std::cout<<j<<lend;}

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

using namespace std;

vector<int> sieves_nonprime(int n) {
    /* sieve of Eratosthenes */
    // returns is_prime([0, n))
    if (n <= 2)
        return vector<int>(n, false);

    vector<int> is_prime(n, true); is_prime[0]=is_prime[1]=false;

    for (long long i=2; i*i<n; ++i)
        if (is_prime[i])
            for (long long j=i*i; j<n; j+=i)
                is_prime[j] = false;

    return is_prime;
}

int main() {
    size_t n=1e6;
    vector<int> is_prime=sieves_nonprime(n);
    for (size_t i=1; i<n; ++i)
        is_prime[i] += is_prime[i-1];

    while (true) {
        int n;
        if (scanf("%d", &n) == EOF)
            break;

        printf("%d\n", is_prime[n]);
    }

    return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[1000000];
	int count;


	while(scanf("%d",&n)!=EOF){
		count=n;
		c[0]=c[1]=0;
		for(i=2;i<=n;i++){
			c[i]=1;
		}
		
		for(i=0;i*i<=n;i++){
			if(c[i]==1){
				for(j=i+1;j<=n;j++){
					if(j%i==0){
						c[j]==0;
						count--;
					}
				}
			}
		}

		printf("%d",count);


	}





	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long lint;

int idx;
int prime[5761455];
bool sieve[10002];
bool sieveBig[1000002];

void segmentSieve(lint a, lint b)
{
	memset(sieveBig, 0, sizeof(sieveBig));
	if (a == 1) sieveBig[0] = true;
	for (int i = 2; (lint)i * i < b; i++){
		if (sieve[i]){
			for (int j = max(2ll, (a + i - 1) / i) * i; (lint)j < b; j += i) sieveBig[j - a] = true;
		}
	}
	
	for (int i = 0; i < b - a; i++){
		if (!sieveBig[i]){
			prime[idx++] = (lint)i + a;
		}
	}
}

int main()
{
	for (int i = 3; i <= 10000; i += 2) sieve[i] = true;
	sieve[2] = true;
	
	for (int i = 3; i <= 10000; i += 2){
		if (sieve[i]){
			for (int j = i * 3; j <= 10000; j += 2 * i) sieve[j] = false;
		}
	}
	
	for (int i = 0; i < 100; i++) segmentSieve(1000000 * i + 1, 1000000 * (i + 1) + 1);
	
	
	//int N;
	//scanf("%d", &N);
	
	//for (int i = 0; i < N; i++){
		int a, b;
		while (scanf("%d", &b) == 1){
		    int *low = upper_bound(prime, prime + 5761455, 0) - 1, *up = upper_bound(prime, prime + 5761455, b) - 1;
		    printf("%d\n", up - low);
                }
	//}
	
	
	return (0);
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int MAX_N = int(1e6);

int main(){

    int n, i, j, maxin = 2;
    bool jud;
    vector <int> vec;
    for (i = 2; i <= MAX_N; i++){
        jud = 0;
        for (j = 0; j < vec.size(); j++){
            if (vec[j] * vec[j] > i) break;
            if (!(i % vec[j])){
                jud = 1;
                break;
            }
        }
        if (!jud)
            vec.push_back(i);
    }
    while (cin >> n){
        cout << upper_bound(vec.begin(), vec.end(), n) - vec.begin() << endl;
    }
}

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

#define N 1000000

using namespace std;

int main(){

  int n, root;
  int p[N][2] = {0};

  for(int i=2; i<N; i++){
    p[i][0] = 1;
  }

  for(int i=2; i<N; i++){
    root = (int)sqrt(i) + 1;
    for(int j=2; j<root; j++){
      if(p[j][0] == 1){
        if(i % j == 0){
          p[i][0] = 0;
          break;
        }
      }
    }
  }

  for(int i=2; i<N; i++){
    p[i][1] = p[i-1][1] + p[i][0];
  }

//  for(int i=0; i<30; i++){
//    cout << i << " " << p[i][0] << endl;
//  }

  while(cin >> n){
    cout << p[n][1] << endl;
  }

  return 0;
}

C++: #include <stdio.h>

int isPrime(int n);

int main(void){
    int n;
    int cnt;

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

    return 0;
}


int isPrime(int n){
    int i;
    
    if (n%2==0) return 0;
    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

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

const int NUM = 1000000;

int main() {
  int n;
  bool isPrime[NUM];
  int dp[NUM];
  for (int i=0;i<NUM;i++) {
    isPrime[i] = 1;
    dp[i] = 0;
  }
  isPrime[0] = isPrime[1] = 0;
  for (int i=2;i<NUM;i++) {
    if (isPrime[i]) {
      dp[i] = 1;
      for (int j=i*2;j<NUM;j+=i) {
        isPrime[j] = 0;
      }
    }
  }
  for (int i=1;i<NUM;i++) {
    dp[i] += dp[i-1];
  }

  while (cin >> n) {
    cout << dp[n] << endl;
  }
  return 0;
}

C++: 
#include<iostream>
using namespace std;
int sushu[1000010];
int n;
bool isPrime(int a){
	if (sushu[a] != -1){
		return sushu[a] == 0 ? false : true;
	}
	int i;
	for (i = 2; i < a; ++i){
		if (a%i == 0){
			sushu[a] = 0;
			return false;
		}
	}
	sushu[a] = 1;
	return true;
}
int main()
{
	memset(sushu, -1, sizeof(sushu));
	while (cin >> n){
		for (int i = 2; i <= n; ++i){
			if (isPrime(i))
				cout << i << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	while(cin>>n){
		int cnt=0;
		vector<bool> v(n+1,true);
		for(int i=2; i<=sqrt(n); i++){
			if(v[i]){
				for(int j=2; i*j<=n;j++){
						v[i*j]=false;
				}
			}
		}
		for(int i=2;i<=n;i++){
			if(v[i])
				cnt++;
		}
		cout << cnt << endl;
	}
}

C++: #include <cstdio>

int main(void) {
	int n, ans = 0;
	scanf("%d", &n);
	for(int i = 2; i < n; i++) {
		bool flag = false;
		for(int j = 2; j < i; j++) {
			if(i % j == 0)
				flag = true;
		}
		if(flag)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}