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 <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

#define MAXINT 1000000
bool isprime[MAXINT];
ll int sum[MAXINT];
void makeprime(){
	REP(i,MAXINT) isprime[i] = true;
	FOR(i,2,sqrt(MAXINT)+1){
		if(!isprime[i]) continue;
		FOR(j,i+1,MAXINT-1){
			if(j%i==0) isprime[j] = false;
		}
	}
}

int main(){
	makeprime();
	sum[0] = 0;
	sum[1] = 0;
	sum[2] = 1;
	/*FOR(i,3,MAXINT){
		if(isprime[i]) sum[i] = sum[i-1]+1;
		else sum[i] = sum[i-1];
	}*/
	ll int n;
	while(cin >> n){
		ll int ans = 0;
		REP(i,n) if(isprime[i]) ans++;
		cout << ans << endl;
	}
}

C++: #include<iostream>
using namespace std;
bool num[1000001];
int main(){
  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 ans = 0;
    for(int i=2; i<=n; i++)
      if(!num[i]) ans++;
    cout <<ans<<endl;
  }
  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(std::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 <stdio.h>
#include <vector>

using namespace std;

vector<int> ps;

int isprime(int n){
	vector<int>::iterator it;
	for(it=ps.begin();it!=ps.end();it++){
		if(n%(*it) == 0) return 0;
	}
	ps.push_back(n);
	return 1;
}

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

	int c=0;
	for(int i=2;i<=n;i++)
		if(isprime(i)) c++;

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

C++: #include <iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define MAX 1000000

bool is_prime[MAX];
ll prime[MAX];

ll found(ll a)
{
    ll p=0;
    for(ll i=0;i<=a;i++)
    {
        is_prime[i]=true;
    }
    is_prime[0]=false;
    is_prime[1]=false;
    for(ll i=2;i<=a;i++)
    {
        if(is_prime[i])
        {
            prime[p++]=i;
            for(ll k=2*i;k<=a;k=k+i)
            {
                is_prime[k]=false;
            }
        }
    }
    return p;
}

int main()
{
    ll n;
    while(cin>>n)
    {
        ll q;
        q=found(n);
        cout<<q<<endl;
    }
    return 0;
}

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

using namespace std ;

int main(){
	int n,cou=0 ;
	cin >> n ;

	/*üÍª1ÈºÈçÎfÍÈµ*/
	if(n <= 1){ return 0 ; }

	/*zñÉQðüêé*/
	vector<int> num ;
	num.push_back(2) ;

/*zñÉüÍµ½ÜÅÌïðüêé*/
	for(int i = 3 ; i <= n ; i+=2){
		num.push_back(i) ;
	}

	/*zñÌfÈOÌªÉ0ðüêé*/
	for(int i = 3 ; i <= n ; i+=2) {
		if(num[i/2] != 0){
			for(int j = 3 ; i * j <= n ; j+=2) {
				num[(i*j)/2] = 0 ;
				cou++;
			}
		}
	}

	/*0ÈOð\¦ifÌ\¦j*/
	
	cout << num.size()-cou << endl;
	
	return 0 ;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX_N = 1e6+5;
int prime[MAX_N];
bool is_prime[MAX_N];
int sieve(){
    memset(is_prime, true, sizeof(is_prime));
    int p = 0;
    is_prime[0] = is_prime[1] = false;
    for(int i = 2;i < MAX_N;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j = 2*i;j < MAX_N;j+=i){
                is_prime[j] = false;
            }
        }
    }
    return p;
}

int main(){
    int n;

    while(~scanf("%d",&n)){
            int p = sieve();
//        printf("test :\n");
//        for(int i = 0;i < 10;i++){
//            printf("%d ",prime[i]);
//        }
//        cout <<endl;
        int num = upper_bound(prime, prime + p, n) - prime;
        printf("%d\n",num);
    }
}

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

using namespace std;

void init(int *m) {
    m[1] = 0;
    m[2] = 1;
    for (int i = 3; i <= 1000000; i += 2)
        m[i] = 1;

    for (int i = 3; i <= 1000; i += 2) {
        if (m[i] == 0)
            continue;
        for (int j = 2; i * j <= 1000000; j++)
            m[i * j] = 0;
    }

    for (int i = 3; i <= 1000000; i++)
        m[i] += m[i-1];
}

int main() {

    #if 0
        ifstream cin("34870.in");
    #endif

    int *memo = new int[1000001];
    init(memo);

    int n;
    while (cin >> n) {
        cout << memo[n] << endl;
    }

    return 0;
}

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

//??¨??????????????????????????§?´???°??¨?????????
//?´???°??¨??¨?´???????????????£?????????????????§??¨????????????

const int MAX_V = 10000000;
int prime[MAX_V + 1]; //?´???°??¨
int sum[MAX_V + 1]; //?´???°?????°???????¨?

int main()
{
	int i, k, v;
	prime[0] = prime[1] = 0;
	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;
			}
		}
	}

	sum[0] = 0;
	for (i = 0; i < MAX_V + 1; i++)
	{
		sum[i+1] = sum[i] + prime[i+1];
	}

	int input;
	while (cin >> input)
	{
		cout << sum[input] << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int sang(int n,bool *s,int *p,int &m){
	m = 0;
	for(long i = 2; i<=n;i++){
		s[i] = 2;
	}
	for(long i = 2; i<=n; i++){
		if(s[i]){
			p[m++] = i;
			for(long j = i * i; j<= n ; j += i){
				s[j] = 0;
			}
		}
	}
	return m;
}
int main(){
	int test =0;
	bool s[100005];
	int n,p[100005],m;

	while(test <=30){
		cin>>n;
		sang(n,s,p,m);
		cout<<m<<endl;
		test++;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
        int n;
        int d; //素数を入れるための添字
        bool count; //割りきれるかどうかの判定
        int number[400000]; //素数を入れておく
        number[0] = 2;
        
        
        while(cin >>n != 0){
                d = 0;
                for(int i = 3; i <= n; i++){
                        count = true;
                        for(int j = 0; j <= d; j++){
                                if(i % number[j] == 0){
                                        count = false;
                                }
                        }
                        if(count == true){
                                d++;
                                number[d] = i;
                        }
                }
        cout << d+1 << endl;
        }
        return 0;
}

C++: #include<cstdio>
using namespace std;
bool us[1000000]={false};
int p[1000000] = {0};
int main(){
	/*Eratosthenes*/
	p[0] = 2;
	for(int i = 0; i <= 1000000; i+=2){
		us[i] = true;
	}
	
	int cnt = 1;
	for(int i = 3; i <= 1000000; i+=2){
		int q = 0;
		if(us[i] == true)continue;
		else if(us[i] == false){
			p[cnt] = i;
			cnt++;
			us[i] = true;
			q = i;
			for(int j = q+q; j <= 1000000; j += q){
				us[j] = true;
			}
		}
	}
	
	int n;
	while(~scanf("%d",&n)){
		int x = 0;
		while(1){
			if(p[x] > n)break;
			x++;
		}
		printf("%d\n",x);
	}
	return 0;
}