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>
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=0;
      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 <iostream>

using namespace std;

int main(){
	int n , ans = 1;

	cin >> n;

	if(n <= 1){
		ans--;
	}

	for(int i = 2; i <= n; i++){
		if(i % 2 != 0 && 9 > i){
			//cout << i << endl;
			ans++;

		}if(i >= 9){
			if(i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0){
				//cout << i << endl;
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  while (cin >> n) {
    int prime_table[1000000] = {};
    for (int i = 2; i <= n; i ++) {
      if (prime_table[i] == 0) {
        for (int j = 2; j <= n / i; j ++) {
          prime_table[i * j] = 1;
        }
      }
    }
    int count = 0;
    for (int i = 2; i <= n; i ++) {
      if (prime_table[i] == 0) {
        count += 1;
      }
    }
    cout << count << endl;
  }
}

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

int main()
{
	std::uint32_t n;
	while (std::cin >> n) {
		std::uint32_t num_prime = (n > 1) ? 1 : 0;
		std::vector<std::uint8_t> is_prime(n / 2, true);
		for (std::uint32_t i = 3; i < n + 1; i += 2) {
			if (is_prime[i / 2 - 1]) {
				++num_prime;
				for (std::uint32_t j = 3 * i; j < n + 1; j += i + i) {
					is_prime[j / 2 - 1] = false;
				}
			}
		}
		std::cout << num_prime << std::endl;
	}
	return 0;
}

C++: #include<stdio.h>
int prime[1000000];
int main(){
	prime[0]=-1;
	prime[1]=-1;
	for(int i=2;i<1000000;i++){
		if(prime[i]==0){
			prime[i]=1;
			for(int j=i*2;j<1000000;j+=i)prime[j]=-1;
		}
	}
	int now;
	while(~scanf("%d",&now)){
		int ans=0;
		for(int i=1;i<now+1;i++)if(prime[i]==1)ans++;
		printf("%d\n",ans);
	}
}

C++: #include <stdio.h>

int main(void) {
	int n,i,c,k,t;
	while(scanf("%d",&n) != EOF){
	i = 0;
	for(c = 2; n >= c; c++){
		t = 0;
		for(k = 2; c/2 >= k; k++){
			if(c%k == 0){t =1;break;}
		}
		if(t == 0)i++;
	}

	printf("%d\n",i);
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int ans=0,math[1001000]={0};
    math[1]=1;
    for(int i=2;i<n+1;i++){
      int bell=i;
      if(math[i]==0){
	ans++;
	math[i]=1;
      }
      while(bell<=n){
	bell+=i;
	if(math[bell]==0){
	  math[bell]=1;
	}
      } 
    }
    cout << ans << endl;
  }
}

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

using namespace std;

int main()
{
	bool a[1000000];
	int n;
	
	fill(a, a+1000000, false);
	a[2] = true;
	for(int i = 3; i < 1000000; i+=2){
		bool f = true;
		for(int j = 3; j*j <= i; j+=2){
			if(i%j == 0){
				f = false;
				break;
			}
		}
		a[i] = f;
	}
	
	while(cin >> n){
		int c = 0;
		for(int i = 2; i <= n; i++){
			if(a[i]){
				c++;
			}
		}
		cout << c << endl;
	}
	
	return 0;
}

C++: using System;
using System.Collections;

class main
{
    static void Main(String[] args)
    {
        while (true)
        {
            string s = Console.ReadLine();           
            if (s != null)
            {
                int c = 0;
                int f = 0;
                int n = int.Parse(s);
                int r = (int)Math.Sqrt(n);
                ArrayList  p = new ArrayList();
                if (n > 1)
                {
                    for (int a = 2; a <= n; a++)
                    {
                        p.Add(a);
                    }
                    while (true)
                    {
                        f = (int)p[0];
                        c++;
                        for (int i = 0; i < n; i++)
                        {
                            p.Remove(f * i);
                        }
                        if (f > r)
                        {
                            break;
                        }
                    }
                    Console.WriteLine("{0}",c+p.Count);
                }
                if (n <= 1)
                {
                    Console.WriteLine(0);
                }
            }
            if (s == null)
            {
                break;
            }
        }
        Console.ReadKey();
    }
}

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


int main()
{

	int i,n,count,num;
	deque<int> sosu;
	deque<int>::iterator it;
	bool flg;
	
	while(cin >> n){
		sosu.clear();
		if( n <= 2 ) {
			if( n == 2 ) {
				count = 1;
			}
			else 
				count = 0;
		}
		else {
			for( i = 3; i <= n ; i+=2 ) {
				flg = true;	
				for(it = sosu.begin(); it != sosu.end(); it++ ) {
					num = *it;
					if( i < 2 * num ){
						break;
					}
					if( (i % num ) == 0 ){
						flg = false;
						break;
					}				
				}
				if( flg == true ) {
					sosu.push_back( i );
				}
			}
			count = sosu.size() + 1;
		}
		cout << count << endl;
	}
			
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int N;
    int count=0;
    cin >> N;
    bool* IsPrime = new bool[N];
    IsPrime[0] = false;
    IsPrime[1] = false;
    for(int i=2; i<=N;i++){
      IsPrime[i] = true;
    }
    for(int i=2; i*i<=N;i++){
      if(IsPrime[i]){
        for(int j=2*i; j<=N; j+=i)
          IsPrime[j] = false;
        }
    }
    for(int i=0; i<=N;i++)
      if(IsPrime[i]) count++;
    
    cout << count << endl;
    delete[] IsPrime;
    return 0;
}