Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

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

// bool isPrime(unsigned int n);

int main()
{
    int n;
    while(cin>>n){
        vector<int> primeTable;
        if( n==1 ){ cout << "0" << endl; continue; }
        primeTable.push_back(2);
        for(int i=3; i<=n; i++){
            vector<int>::iterator j;
            for(j=primeTable.begin(); j!=primeTable.end(); j++){
                if(!(i%(*j))) break; // i%j!=0
            }
            if( j==primeTable.end() ) primeTable.push_back(i);
        }
        cout << primeTable.size() << endl;
    }
    

    return 0;
}

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

#define rep(i, n) for(int i = 2; i <= n; i ++)

using namespace std;

int main(void){
	for(int n, count = 0; cin >> n; cout << count << endl, count = 0){
		vector<bool> numberList(n + 1);

		rep(i, n) numberList[i] = true;

		for(int i = 2; i * i <= n; i ++) for(int j = i; i * j <= n; j ++) if(numberList[i * j]) numberList[i * j] = false; 
		
		rep(i, n) if(numberList[i]) count ++;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
int main()
{
    long long int low, high, i, flag,c, s ;
    while(scanf("%lld",  &high)!=EOF){
    long long int start = 2;

    c = 0;


    while (start <= high)
    {
        flag = 0;
        s = sqrt(start);
        for(i = 2; i <= s; i++)
        {
            if(start% i == 0)
            {
                flag = 1;
                break;
            }
        }

        if (flag == 0)
        {
              c++;
        }
        start++;

    }
    printf("%lld\n",c);

    }

C++: #include <iostream>
#include <algorithm>
using namespace std;
vector<int> prime;
void init(){
	for(int i=2;i<999999;i++){
		bool isprime=true;
		for(vector::iterator p(prime.begin());p!=prime.end();p++){
			if(i%*p==0){
				isprime=false;
				break;
			}
		}
		if(isprime){
			prime.push_back(i);
		}
	}
}
int main(){
	int n;
	init();
	while(cin>>n){
		cout<<lower_bound(prime.begin(),prime.end(),n)-prime.begin()+1<<endl;
	}
	return 0;
}

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

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

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

int IsPrime(int n){
    int i;

    for(i = 3; i * i <= n; i += 2)
         if(n % i == 0)
            return 0;
    return 1;
}

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

		for(int i=3;i<in;i+=2)
			if(IsPrime(i) == 1)
				++c;

		if(in >= 2)	++c;
		
		cout << c << endl;
	}

	return 0;
}

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

//using namespace std;

int sosuu(int n);

int main(){
    int n = 0;
    
    while(scanf("%d",&n)!=EOF){
        int temp = 0;
        if(n==1){
            printf("%d\n",0);
        }else{
            for(int i=2; i<=n; i++ ){
                temp+=sosuu(i);
                if(i!=2){
                    i++;
                }
            }
            printf("%d\n",temp);
        }
    }
}

int sosuu(int n){
    for(int i=2; i<sqrt(n); i++){
        if(n%i == 0){
            return 0;
        }
        if(i!=2){
            i++;
        }
    }
    return 1;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long lon
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)

using namespace std;

int main (void){
    
    int number[40] = {0};
    int answer[40] = {0};
    int i = 0,j = 0,k = 0;
    while(cin >> number[i])
    {
        for(k = number[i]; k>1;k--)
            for(int l = k-1;l>0;l--)
            {
                if(k == 2 && l == 1)
                {
                    answer[i]++;
                    break;
                }
                if(k % l == 0)
                    break;
                if(l == 2)
                {
                    answer[i]++;
                }

            }
        i++;
    }
    REP(j,i)
    cout << answer[j]<< endl;
    return 0;
    
}

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

int main(){
	int n;
	while ( cin >> n ){
		int cnt = 0;
		if ( n >= 2 ) ++cnt;
		for ( int i = 3; i <= n; i += 2 ){
			bool prime = true;
			for ( int j = 3; j <= sqrt( static_cast< double >( i ) ); j += 2 ){
				if ( !( i % j ) ){
					prime = false;
					break;
				}
			}
			if ( prime ) ++cnt;
		}

		cout << cnt << endl;
	}
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,sum;
    int b[999999];
    b[0]=0;
    for(int i=1;i<999999;i++){
        b[i]=prime(i);
    }
    while ( cin >> a){
        sum =0;
        for (int i=1;i<a;i++){
            sum +=b[i+1];
        }
        cout << sum << endl;
    }
}
int prime(int x){
    if(x==1)
        return 0;
    if(x==2 || x==3 || x==5 || x==7)
        return 1;
    if(x%2==0 || x%3==0)
        return 0;
    for (int i=5;i<=sqrt(x)+1;i+=6){
        if(x%i==0 || x%(i+2)==0)
            return 0;
    }
    return 1;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
 
 
// cin >>
// cin <<
bool isPrime(int x){
    if(x==2) return true;
    if(x<2||x%2==0) return false;
    int i=3;
    while(i<=sqrt(x)){
         if (x%i==0)return false;
        i= i+2;
    }
    return true;
}
int main(){
    int in[30]={};
    int out=0;
	int max=0;
	bool flag[10000001];
    for(int i=0;i<30;i++){
		cin >>in[i];
		if(i==0){
			max=in[i];
		}else{
			if(in[i]>max){
				max=in[i];
			}
		}
	}
	for(int j=0;j<max;j++){
		if(isPrime(j)==true){
			flag[j]=true;
		}else{
			flag[j]=false;
		}
    }
	
    for(int i=0;i<30;i++){
		out=0;
		for(int j=0;j<in[i];j++){
			 if(flag[j]==true){
				 out++;
			 }
		}
       cout <<out <<endl;
    }
     
    return 0;
}

C++: #include <iostream>
#include<algorithm>
using namespace std;
#define MAX 10000000
bool prime[MAX]={true};

int countPrime(int n){
	if(n<2) return 0;
	if(n==2) return 1;
	int ret=0;
	// fill(data, data + numof(data), 0);
	fill(prime, prime+MAX,true);
	for(int i=2;i*i<=n;i++){
		if(prime[i]){
			for(int j=i*i;j<=n;j=j+i){
				prime[j]=false;
			}
		}
	}
	for(int i=2;i<=n;i++){
		if(prime[i]) ret++;
	}
	return ret;
}

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

C++: #include<iostream>
#include<cmath>
#define FOR(x,s,g) for(int x=(s);x<=(g);x++)
using namespace std;

int main(){
  int n;
  while(cin>>n){
    int count=0;
    FOR(i,2,n){
      bool flag=false;
      FOR(j,2,sqrt(i)){
	if(i%j==0){
	  flag=true;
	  break;
	}
      }
      if(!flag) count++; 
    }
    cout<<count<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
// エラトステネスのふるい
int main() {
  int num = 1000000;
  int n, prime[num];
  while (cin >> n) {
    for (int i = 0; i < num; i++) {
      prime[i] = 0;
    }
    prime[0] = 1;
    prime[1] = 1;
    
    int count = 0;
    for (int i = 0; i <= n; i++) {
      if (prime[i] == 0) {
	count++;
	for (int j = i; j <= n; j += i) {
	  prime[j] = 1;
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}