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 <math.h>
#include <vector>
using namespace std;
int count=0,num=0;
int main()
{
	while(cin>>num)
	{
		count=0;
		vector<bool> a(num+1,true);
		for(int i=2;i<=sqrt(num);i++)
		{
			
			if(a[i]==true)
				for(int j=i*i;j<=num;j+=i)
				{
					
					a[j]=false;
				}
				
		}
		for(int  i=2;i<=num;i++)
		{
			cout<<a[i];
			if(a[i]==true)
				count++;
		
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int hako[1000100];
int main(){
	int n;
	while(cin >> n){
		int ret = 0;
		REP(i,1000100)hako[i] = 0;
		for(int i=2;i<=n;i++){
			if(hako[i] == 1)continue;
			ret++;
			for(int j=i;j <= n;j+=i){
				hako[j] = 1;
			}
		}
		cout << ret << endl;
	}
	return 0;
}

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

#define MAX 1000000



int main(void){

	bool p[MAX+1];
	int n,ans;

	for(int i=0;i<=MAX;i++){
		p[i]=(i<=1)?false:true;
	}

	for(int i=2;i<=(sqrt((double)MAX))+1;i++){
		if(p[i]){
			for(int j=i*2;j<=MAX;j=j+i){
				p[j]=false;
			}
		}
	}

	while(cin>>n){
		ans=0;
		for(int i=0;i<=n;i++){
			if(p[i]){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>                                             
using namespace std;                                            
                                                                
bool IsPrime(int n) {                                           
  if (n==2) {                                                   
    return true;                                                
  }                                                             
  if (n<2 || n%2==0) {                                          
    return false;                                               
  }                                                             
  for (int k=3; k*k<=n; k+=2) {                                 
    if (n%k==0) {                                               
      return false;                                             
    }                                                           
  }                                                             
  return true;                                                  
}                                                               
                                                                
int main() {                                                    
  int n;                                                        
  while (cin >> n) {                                            
    int ans = 0;                                                
    for (int i=0; i<=n; i++) {                                  
      if (IsPrime(i)==true) {                                   
        ans++;                                                  
      }                                                         
    }                                                           
    cout << ans << endl;                                        
  }                                                             
  return 0;                                                     
}

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

using namespace std;

const int N_MAX = 1000000;

int table[N_MAX];

int main() {
  for (int i = 0; i < N_MAX; i++) {
    table[i] = 0;
  }
  table[0] = table[1] = 1;
  int sq = sqrt(N_MAX);
  for (int i = 2; i < sq+1; i++) {
    if (table[i] == 0) {
      for (int j = i*2; j < N_MAX; j += i) {
        table[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n) {

    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (table[i] == 0) ans++;
    }
    cout << ans << endl;

  }

  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define MAX_N 100001
int main(){
	int n;
	while(cin >> n){
		vector<int> vec;
		vector<int>::iterator it =vec.begin();
		for(int i=2;i<=n;i++){
			int flag=0;
			it =vec.begin();
			while(it!= vec.end()){
				if(i% *it==0){
					flag=1;
					break;
				}
				it++;
			}
			if(!flag)vec.push_back(i);
		}
		it =vec.begin();
		//while(it!= vec.end()){
		//	cout<<*it<<endl;
		//	it++;
		//}
		cout << vec.size()<<endl;
	}

C++: #include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=10000000;
bool is_prime[maxn];
int solve(int n){
	for(int i=0;i<=n;i++)is_prime[i]=true;
	int ans=0;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			ans++;
			for(int j=i*2;j<=n;j+=i)is_prime[j]=false;
		}
	}
	return ans;
}


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

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

int main(){
  int n;
  int i,j;
  while(scanf("%d", &n) != EOF){
    int m=2;
    for(i=2;i<=n;i++){
      for(j=2;j<=(int)sqrt((double)i);j++){
	if(i%j == 0)
	  break;
	if(j==(int)sqrt((double)i) && i%j!=0)
	  m++;
      }
    }
    printf("%d\n",m);
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())


int mem[1000000];
int ans[1000000];

int main(int argc, char const *argv[])
{
	int max_num = 1000000;
	int loop_max = sqrt(1000000);
	memset(mem, 0, 1000000);
	for (int i = 2; i < loop_max; i++)
	{
		int c = i * i;
		while(c < max_num)
		{
			mem[c] = 1;
			c+= i;
		}
	}
	int n;
	int sum = 0;
	ans[0] = ans[1] = 0;
	for (int i = 2; i < max_num; i++)
	{
		sum += mem[i] ? 0 : 1;
		ans[i] = sum;
	}
	while(scanf("%d", &n) != EOF)
	{
		printf("%d\n", ans[n]);
	}
	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef vector <int> vi;
vi primes;

int get_primes(int max){
	int n = (max+1)/2;
	int root = (int)(pow(n, 0.5));
	vector <bool> numbers(n, true);
	numbers[0]=false;

	if (max>1) primes.push_back(2);
	for (int i=1; i<root; i++){
		int tmp = i*2+1;
		if (numbers[i]){
			primes.push_back(tmp);
			for (int j=i+tmp; j<n+1; j+=tmp){
				numbers[j]=false;
			}
		}
	}
	for (int i=root; i<n+1; i++){
		if(numbers[i]){
			primes.push_back(2*i+1);
		}
	}
	return 0;
}

int main(void){
	vi n;
	int nmax=0;
	while (true){
		int tmp;
		cin>>tmp;
		if (cin.eof()) break;

		n.push_back(tmp);
		if (tmp>nmax) nmax=tmp;
	}

	get_primes(nmax);
	for (int i=0; i<n.size(); i++){
		cout<<upper_bound(primes.begin(), primes.end(), n[i]) - primes.begin()<<endl;
	}
	return 0;
}

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

int main(){
    int n=11, t;
    while(cin >> n){
      t = 0;
      for(int i = 2;i <= n;++i){    
        for(int j = 2;j < i;++j){
          if(i % j == 0) break;
          if(j == i - 1) ++t;
        }
      }
      if(n >= 2) ++t;
      cout << t << endl;
    }
  return 0;
}