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<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
#define MAX 1000000
bool sosu[MAX]={false};
int main(){
  for(int i=3;i<MAX;i+=2){
    if(sosu[i])continue;
    for(int j=i*3;j<MAX;j+=i*2)
      sosu[j]=true;
  }
  for(int i=4;i<MAX;i+=2)
    sosu[i]=true;
  int in;
  while(cin>>in){
    int co=0;
    loop(i,2,in+1)if(!sosu[i])co++;
    cout<<co<<endl;
  }


}

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

int main()
{
	bool is_prime[1000000];
	memset(is_prime,false,sizeof(is_prime));
	for(int i=2;i<1000000;i++){
		if(!is_prime[i]){
//			cout<<i<<endl;
			for(int m=i*2;m<1000000;m+=i){
				is_prime[m]=true;
			}
		}
	}
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=2;i<=n;i++){
			if(!is_prime[i]) ans++;
		}
		cout<<ans<<endl;
	}
}

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

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


int main()
{
	int Data = 0;

	while (cin >> Data)
		count_Prime(Data);

	return 0;
}

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

	cout << counter << endl;

}

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

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

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

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	
	for (int i = 2; i*i <=MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i+i; j*j <=MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	/*int sum = 0;
	for (int i = 2; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}*/
	int n;
	
	while (cin >> n){
		int sum = 0;
		for (int i = 2; i <= n; i++){
			if (prime[i]){
				sum++;
			}
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600

#define MAX_PRIME 1000000

vector<int> primes;
vector<bool> isPrime(MAX_PRIME+1, true);

// sieve of Erastosthenes
inline void prime_list(){
  const int sz = MAX_PRIME;
  isPrime[0]=isPrime[1]=false;
  for(int i=4;i<=sz;i+=2) isPrime[i]=false;
  primes.pb(2);
  for(int i=3; 2*i<=sz; i+=2){
    if(isPrime[i]){
      primes.pb(i);
      for(long j=(long)i*i; j<=sz; j+=i) isPrime[j]=false;
    }
  }
}

int main(){
  prime_list();
  int d;
  while(cin>>d){
    cout << upper_bound(all(primes), d) - primes.begin() << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cctype>
using namespace std;


int n,cnt;
bool is_prime[1000005];

void mk_prime(int n){
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++) is_prime[i]=true;
    for(int i=2;i*i<=n;i++) if(is_prime[i]){
        for(int j=i*i;j<=n;j+=i){
            is_prime[j]=false;
        }
    }
}

int main(){
    mk_prime(1000005);
    while(cin>>n){
        cnt=0;
        for(int i=2;i<=n;i++){
            if(is_prime[i]) cnt++;
        }
        cout <<cnt<<endl;
    }
    return 0;
}

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

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
	p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num){
	// num???????´???°?????°
	int count = 0;
	
	// Route Num?????´??°??¨??????????????????
	int routeN_int = (int)sqrt(num);
	//cout << routeN_int << endl;
	
	// ???n?????§?????´??°?????????????´???°????????°????????????
	vector<bool> prime_flag_set(num + 1, true);
	
	for(int i = 0; i < prime_flag_set.size(); i++){
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}
	//cout << endl;
	// 1???2 ?????? n ?????§?????´??°????????????p????????°????????? = false
	for(int p = 2; p < prime_flag_set.size(); p++){
		if( prime_flag_set[p] == false){
			continue;
		}
		int j = 2;
		// 3???2??????????????°?????????????????????p ??? ???n ????¶????????????????
		while(p < routeN_int){
			if(p*j > num+1){
				// num??\???
				break;
			}
			prime_flag_set[p * j] = false;
			//p????????°????±???????
			j++;
		}
	}
	// 2??\???
	for(int i = 2; i < prime_flag_set.size(); i++){
		if(prime_flag_set[i] == true){
			count++;
		};
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}
	
	return count;
}

int main(){
	int num = 0;
	while(cin >> num){
		cout << SieveOfEratosthenes(num) << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(void)
{
	int n;
	while(cin >> n){
		int sosu = 0;
		for(int i = 2; i <= n; i++){
			int count = 0;
			if(i % 2){
				for(int j = 1; j <= i; j++){
					if(i % j == 0) {
						count++;
					}
				}
				if(count == 2) sosu++;
			}
		}cout << sosu+1 << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
  int n;
  bitset<1000000> is_prime;
  is_prime.set();
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i< 1000000; i++) {
    for (int j = i * 2; j < 1000000; j += i) {
      is_prime[j] = false;
    }
  }
  while (scanf(" %d ", &n) == 1) {
    int c = 0;
    for (int i = 0; i <= n; i++) {
      if (is_prime[i]) {c++;}
    }
    printf("%d\n", c);
  }
  return 0;
}