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<iostream>
using namespace std;
int d[1000000]={},p[1000000]={};
void calc(){
    for(int i=2;i<1000000;i++){
        if(d[i]==0){
            for(int j=2;j<1000000;j++){
                if(i*j>1000000) break;
                    d[i*j]=1;
            }
        }
    }
    for(int i=2;i<1000000;i++){
        if(d[i]==0)
        p[i]=p[i-1]+1;
        else
        p[i]=p[i-1];
    }
}
int main(){
    calc();
    int n;
    while(cin>>n,n){
        if(cin.eof())break;
        cout<<p[n]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <bitset>
#include <fstream>

using namespace std;

#define NUM_LIMIT 1000000   // numbers < NUM_LIMIT

int getNumOfPrimes(bitset<NUM_LIMIT> &isPrime, int min, int max){
    int cnt = 0;
    for (int i = 2; i <= max; i++){
        if (!isPrime[i]) continue;  // skip non prime numbers
        cnt ++;
        if (i >= min){
            // cross out the multiples of the number
            for (int j = 2; i*j <= max; j++){
                isPrime[i*j] = 0;
            }
        }
    }
    return cnt;
}

int main(){
    //ifstream cin("input.txt");
    bitset<NUM_LIMIT> isPrime;
    isPrime.set();  // set all bits to 1
    
    // input data
    int number;
    int max_num = 0;
    while(cin >> number){
        int cnt = 0;
        if (number > max_num){
            cnt = getNumOfPrimes(isPrime, max_num+1, number);
            max_num = number;
        } else {
            cnt = getNumOfPrimes(isPrime, number+1, number);
        }
        cout << cnt << endl;
    }
    return 0;
}

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

#define N 999999+1
int prime[N];
void sieve(int en) {
  // prime[prime number] = 0
  // prime[not prime number] = 1
  for(int i=2;i<=(int)sqrt(en);i++) {
    for(int j=i*2;j<=en;j+=i) {
      prime[j] = 1;
    }
  }
}

int main() {
  int n;
  int max_n = 2;
  while(cin >> n) {
    if(n > max_n) {
      sieve(n);
    }
    int cnt = 0;
    for(int i=2;i<=n;i++) {
      if(prime[i] == 0)
        cnt++;
    }
    cout << cnt << endl;
  }
}

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

int a[999999]={};

int main(){
	int n,ans=0;
	for(int i = 2; i*i < 999999; i++){
		for(int j = 0; j < 999999; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		for(int i = 2; i <= n; i++){
			if(a[i]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int data[999999] = { -1 };
bool notprime[999999] = { false };

int main(int argc, char **argv){
	int n;
	int cnt;
	while (cin >> n) {
		cnt = 0;
		for (int i = 2; i < n; i++) {
			if (!notprime[i]) {
				cnt++;
				for (int j = 2; j <= n / i; j++) {
					notprime[i * j] = true;
				}
			}
			if (i >= sqrt(n)) {
				for (int k = i + 1; k <= n; k++) {
					if (!notprime[k]) {
						cnt++;
					}
				}
				break;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){
	int n;
	
	while(scanf("%d",&n)==1){
	int count=0;
	double sqrtn = n;
		for(int i=3;i<=n;i+=2){
			bool p=true;
			for(int j=3;j<sqrt(sqrtn);j++){
				if(i % j == 0){
					p=false;
					break;
				}
			}
			if(p) count++;
		}
		printf("%d\n",count+1);
	}
	return 0;
}

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

using namespace std;

#define MAX 1000100
#define LIM 1010

bool composite[MAX + 100];
int prime[MAX + 100];

void sieve()
{
    for(int i = 2; i <= LIM; i++){
        for(int j = i * i; j <= MAX; j += i)
            composite[j] = true;
    }
    int counter = 0;
    for(int i = 2; i <= MAX; i++){
        if(!composite[i]) counter += 1;
        prime[i] = counter;
    }
}

int main()
{
    sieve();
    int n;
    while(cin >> n){
        cout << prime[n] << "\n";
    }
}

C++: /// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
/// http://www.tsg.ne.jp/TT/tsg/c/mansaku/P01.html
#include<cstdio>
#include<cmath>

int main(){
    int n, cnt=0;
    scanf("%d", &n);
    for(int i = 3; i<=n; i+=2){
        int k= 0;
        for(int j=3; j<sqrt(i); j+=2){
            if(i%j==0){
                k=1;
                break;
            }
        }
        if(k==0) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}

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

bool isprime(int x){
	if(x==2) return true;
	if(x<2 && !(x%2)) return false;
	x = int(ceil(sqrt(x)));
	for(int i=3;i<=x;i+=2){
		if(!(x%i)) return false;
	}
	return true;
}

int main(){
	int x,i,cnt;
	while(cin>>x){
		cnt=0;
		for(i=2;i<=x;i++){
			if(isprime(i)) cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<String>
#include<time.h>
#include<math.h>

using namespace std;
int c = 0;
int i = 1;
unsigned long long a = 0;
unsigned long long b = 0;
unsigned long long sosuu[100000] = { 0 };
char fire = 0;
int pattara = 0;

int sub(int c) {

	
	
	
	for (int i = 2; i<=c; i++){
		
		for (int q = 1; q <= sqrt(i); q++) {
			sosuu[pattara] = i;
			if (sosuu[pattara] % 2 == 0 && sosuu[pattara]!= 2) {
				break;
			}
			if (sosuu[pattara] % q == 0) {
				b += 1;
			}

		}

		if (b == 1) {
			
			pattara++;
			
		}
		b = 0;
		
	}

	
	return 0;
}


int main(){
	while (scanf("%d", &c) != EOF){

		sub(c);
		cout << pattara << endl;
		pattara = 0;
		
	}

	return 0;
}

C++: #include<iostream>
#define Max 1000000   

bool prime[Max];  
void IsPrime(){  
     prime[0]=prime[1]=0;prime[2]=1;  
     for(int i=3;i<Max;i++)  
        prime[i]=i%2==0?0:1;  
     int t=(int)sqrt(Max*1.0);  
     for(int i=3;i<=t;i++)  
       if(prime[i])  
         for(int j=i*i;j<Max;j+=2*i)//?化    
            prime[j]=0;  
}

int main(){
	int n;
	IsPrime();
	int time=0;
	while((time<=30)&&(std::cin>>n)){
		int count=0;
		for(int i=2;i<=n;++i){
			if(prime[i]) 
				++count;
		}
		std::cout<<count<<std::endl;
		time++;
	}
}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
	 vector<int> a(100);
	a[0]=2;
	int z=1;
	for(int i=2;i<100000;){
		for(int j=0;j<z;j++){
			if(i%a[j]==0)goto stop;
		}
		a[z]=i;
		z++;
		stop:;
		if(i==2) i++;
		else i+=2;
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=0;i<z;i++){
			if(a[i]>b)break;
			else c++;
		}
		cout<<c;
	}
}

C++: #include <iostream>

using namespace std;

int main(){
  int n,visited,cnt=0;
  
  while(cnt<30){
    int count =0;
    cnt++;
    cin >> n;
    if(n==0)count =0;
    for(int j=2;j<=n;j++){
      visited=0;
      for(int i = 2;i<=n;i++){
	
	if(j%i==0&&j!=i)visited=1;
	else if(j%i==0&&j==i&&visited==0)count++;
	
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int sieve(int n);
int prime[1000000];
bool is_prime[1000000];

int main()
{

	int p = 0;
	for (int i = 0; i <= 999999; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999999; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= 999999; j += i) {
				is_prime[j] = false;
			}
		}
	}
	while (true) {
		int n;
		cin >> n;
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}