Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

C++: #include <stdio.h>
#include <string.h>
#define SIZE_VALUE 1000005

int main(){
    bool prime[SIZE_VALUE];
    int i,count=0,input;
    memset(prime,0,sizeof(prime));
    for(i=2;i*i<SIZE_VALUE;i++){
        if(prime[i]==0)
        for(int j=i*i;j<SIZE_VALUE;j+=i){
            prime[j]=1;
        }
    }
    while(scanf("%d",&input)==1){
        count=0;
    for(i=2;i<=input;i++){
        if(prime[i]==0)
            count++;
    }
    printf("%d\n",count);
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string.h>
using namespace std;
vector<int> prime;
int sieve(int n){
   bool arr[n+1];
   int cnt=0;
   memset(arr,true,sizeof(arr));
   for(int i=2;i<=n;++i){
    if(arr[i]){
        prime.push_back(i);
        cnt++;
    }
    for(int j=0;j<prime.size()&&i*prime[j]<n;j++){
        arr[i*prime[j]]=false;
        if(i%prime[j]==0)break;
    }
   }
   return cnt;
}

int main(){
int num;
int a;
while(true){
    scanf("%d",&num);
    if(!num) break;
    a=sieve(num);
    printf("%d\n",a);
}
return 0;
}

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

const int MAX_V = 10000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<=MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

int main(){
    init();
    int num;
    // while(1){
    while(cin >> num){
        int count=0;
        // scanf("%d", &num);
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

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

#define MAX 1000000

using namespace std;

bool prime[MAX+1];
int T[MAX];

void eratos(int n) {
  for(int i = 0; i < n; i++) prime[i] = false;
  for(int i = 3; i <=n; i+=2)prime[i] = true;
  prime[2] = true;
  for(int i = 3, limit = (int)sqrt(n); i <= limit; i += 2) {
    if(!prime[i]) continue;
    for(int j = i*i, k = i*2; j <= n; j += k) prime[j] = false;
  }
}

void init() {
  eratos(MAX);

  for(int i = 0; i < MAX; i++) {
    T[i] = T[i-1];
    if(prime[i]) T[i]++;
  }
}

int main(void) {
  init();
  int n;
  
  while(cin >> n) cout << T[n] << endl;
  return 0;
}

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

int main() {
	bool prime[1000000]={false};
	prime[1]=true;
	prime[2]=false;
	int n;
	while(cin>>n){
		int cnt=0;
		
		for(int j = 2; j * j <= n ; j++)
            if(!prime[j])
                for (int k = 2; k*j <= n;k++)
                   prime[j*k] = true;
	
		for(int i=2;i<=n;i++)
			if(!prime[i]) cnt++;
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int N,count=0;
	while(cin >> N){
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define N_MAX 100000

using namespace std;

int main(){
	
	int array[N_MAX],i,j,n, num = 0;
	
	while(cin>>n){
		num = 0;
		for (i=0;i<n;i++)
			array[i]=i+2;
		for (i=0;i<n;i++){
			for (j = (i+2); (i+2) * j <= n; j++)
				array[(i+2) * j - 2] = -1;}

	for (i = 0; i < n-1; i++){
    if (array[i] != -1)
	num++;
	}
	cout<<num<<endl;
	}
	cin>>n;
  
	return (0);
}

C++: #include<iostream>

int n;
bool *isPrime;

int solve(){
	int p = 0;
	for(int i=0; i<=n; i++)
		isPrime[i] = true;
	isPrime[0] = isPrime[1] = false;
	for(int i=2; i<=n; i++){
		if(isPrime[i]){
			p++;
			for(int j=2*i; j<=n; j+=i)
				isPrime[j] = false;
		}
	}
	return p;
}

int main(){
	while(std::cin >> n){
		isPrime = new bool[n+1];
		std::cout << solve() << std::endl;
		delete[] isPrime;
	}
	return 0;
}

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

#define MAX (1000000)

int main(void)
{
	char prime[MAX + 1];
	int n;
	char buf[256];
	
	memset(prime, 1, sizeof(prime));
	
	prime[0] = prime[1] = 0;
	for (int i = 2; i * i < MAX; i++){
		if (prime[i] == 1){
			for (int j = i * 2; j <= MAX; j += i){
				prime[j] = 0;
			}
		}
	}
	
	while (fgets(buf, 256, stdin) != NULL){
		int ans;
		
		n = atoi(buf);
		
		ans = 0;
		for (int i = 2; i <= n; i++){
			ans += prime[i];
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

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

bool sieve[1000000];
void makesieve();

int main()
{
	makesieve();
	while(1)
	{
		int n,ans=0;
		std::cin>>n;
		if(std::cin.eof())break;
		for(int i=0;i<=n;i++)
		{
			ans+=sieve[i]?1:0;
		}
		std::cout<<ans<<std::endl;
	}
	return 0;
}

void makesieve()
{
	for(int i=0;i<1000000;i++){sieve[i]=true;}
	sieve[0]=false;sieve[1]=false;
	for(int i=2;i<1000000;i++)
	{
		for(int j=i*2;j<1000000;j+=i)
		{
			sieve[j]=false;
		}
	}
}

C++: #include <iostream>
using namespace std;
int main() {
	int n, count = 0;
	while(cin >> n) {
		for(int i = 2; i < n + 1; i++) {
			count++;
			for(int j = 2; j <= i / 2; j++) {
				if(i % j == 0) {
					count--;
					break;
				}
			}
		}
		cout << count << endl;
		count = 0;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN = 1000000+1000;
const int maxn=100000+5;
int prime[maxn+1];
bool p[MAXN];
int cnt=0;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt]=i;
       	cnt++;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	/*for(int i=0;i<cnt;i++)
	   cout<<prime[i]<<" ";*/
	int n;
	while(scanf("%d",&n)==1){
		int k=lower_bound(prime,prime+cnt,n)-prime;
		if(prime[k]==n) k++;
		printf("%d\n",k);
	}
	return 0;
}

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

int main(){

int i,j,n,count;

while(scanf("%d",&n) != EOF){

count=2;

if(n<4){
	count=n-1;
}else{
	for(i=4;i<n+1;i++){
		for(j=2;j<i/2+1;j++)

			if(i%j==0){
				break;
			}else if(j==i/2)
				count+=1;
	}
}

printf("%d\n",count);

}
return 0;		
}

C++: #include<iostream>
using namespace std;
int main(){
  bool num[1000001] = {false};
  for(int i=2; i<1000; i++){
    if(!num[i]){
      for(int j=i*i; j<1000001; j+=i){
	num[j] = true;
      }
    }
  }
  int n;
  while(cin >>n){
    int sum = 0;
    for(int i=2; i<=n; i++){
      if(!num[i]){sum++;}
    }
    cout <<sum<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  
  while(!cin.eof()) {
    cin >> n;
    list<int> search_list(n-1);
    list<int> prime_number;
    while(n!=1) {
      search_list.push_front(n);
      n--;
    }
    while(!search_list.empty()) {
      int m = search_list.front();
      prime_number.push_back(m);
      search_list.pop_front();
      list<int>::iterator it = search_list.begin();
      while(it!=search_list.end()) {
	if((*it % m) == 0){
	  it = search_list.erase(it);
	  continue;
	}
	it++;
      }				   
    }
    cout << prime_number.size() << endl;
    prime_number.clear();
    search_list.clear();
  }
}