Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [31]int
	var inputCount, primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		resultArr[inputCount] = primeCount
		if inputCount == 30 {
			break
		}
		primeCount = 0
		inputCount++
	}
	for _, v := range resultArr {
		fmt.Printf("%d\n", v)
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

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

int main() {
  const int MAX = 1000000;
  const int SQRT = (int)std::sqrt(MAX);
  bool isPrime[MAX];
  for (int i = 0; i < MAX; i++) {
    isPrime[i] = true;
  }
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < SQRT; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  int n;
  while (std::cin >> n) {
    int cnt = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) cnt++;
    }
    std::cout << cnt << std::endl;
  }
}

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

bool prime[1000001];

void era(){
	for(int i=0;i<1000000;i++)prime[i]=1;
	prime[0]=0;
	prime[1]=0;
	for(int i=0;i<1000000;i++){
		if(prime[i]==true){
			for(int j=i*2;j<1000000;j+=i){
				prime[j]=0;
			}
		}
	}
}

int main(){
	era();
	int n,ans;
	while(cin>>n){
		ans=0;
		for(int i=0;i<n;i++){
			if(prime[i]==1)ans++;
		}
		cout<<ans<<endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    int j,s[1000000];
    long i,n,d=0;
    
    for(i=3;i<1000000;i++){
        for(j=2;j*j<i;j+=2){
            if(j%i==0){
                d--;
                break;
            }
            if(j==2)
                j=1;
        }
        s[i] = ++d;
    }
    
    while(EOF != scanf("%d",&n)){
        printf("%d\n",&d);
    }
    
    
    return 0;
}

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

int is_prime(int n){
    int i;
    int flag = 0;
    for(i=2; i<n; i++){
        if(n%i==0) { flag=1; break; }
    }
    return (flag==1)?0:1;
}


int main(){
	int i, j, n, num = 0, count = 0;
	
	while(1){
		cin >> n;
		if(cin.eof()) break;
		count = 0;
		for(i = 1; i <= n; i++){
			if(is_prime(i) == 1 && i != 1) count ++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int data[100000];
	int count;
	int premaxin=1;


	for(i=0;i<100000;i++){
		c[i]=1;
		data[i]=0;
	}
	c[0]=c[1]=0;

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

		if(premaxin<n){
			for(i=0;i<=n;i++){
				if(c[i]==1){
					if(premaxin>i){
						j=premaxin;
					}else{
						j=i+1;
					}
					for(;j<=n;j++){
						if(j%i==0){
							c[j]=0;
						}
					}
				}
			}

			count=data[premaxin];
			for(i=premaxin+1;i<=n;i++){

				if(c[i]==1){
					count++;
				}
				data[i]=count;
			}
		}

		printf("%d\n",data[n]);
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int get_numprime( int num );

int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		cout << get_numprime( num ) << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 1; // 2はすでにカウント

	for( int i = 3 ; i <= num ; i+=2 )
	{
		int flag = 1;
		for( int j = 2 ; j <= i/2 ; j++ )
		{
			if( i%j == 0 )
			{
				flag = 0;
				break;
			}
		}
		if( flag == 1 ) numprime++;
	}

	return numprime;
}

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

using namespace std;

const int N = 1e6;
const int SQRTN = ceil(sqrt((double) N));
bool isPrime[N + 1];
int prefixsum[N + 1];

// Eratosthenes筛选法
void esieve(void)
{
    memset(isPrime, true, sizeof(isPrime));

    isPrime[0] = isPrime[1] = false;
    for(int i=2; i<=SQRTN; i++) {
        if(isPrime[i]) {
            for(int j=i*i; j<=N; j+=i)  //筛选
                isPrime[j] = false;
        }
    }
}

void maketable()
{
    prefixsum[0] = 0;
    for(int i = 1; i <= N; i++)
        prefixsum[i] = isPrime[i] ? prefixsum[i - 1] + 1 : prefixsum[i - 1];
}

int main()
{
    esieve();

    maketable();

    int n;
    while(~scanf("%d", &n))
        printf("%d\n", prefixsum[n]);

    return 0;
}

C++: #include<cstdio>
using namespace std;
const int N = 1000000;
int IsPrime[N];
int main(){

  IsPrime[0] = 1;
  IsPrime[1] = 1;
  for(int i=2; i<=N;i++){
    if(IsPrime[i]==0){
      for(int j=2*i; j<=N; j+=i)
        IsPrime[j] = 1;
      }
  }
  int max;
  while(~scanf("%d",&max)){
    int count=0;
    for(int i=1; i<max+1; i++)
      if(IsPrime[i]==0) count++;
    printf("%d\n",count);
  }
}

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

int main()
{
	int count=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<0<<endl;
		}

		else{
		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(i);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				count++;
		}
		cout<<count<<endl;
		count=1;}
	}
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

bool t[1000000];

int main(){
	memset(t,1,sizeof(t));
	t[0] = t[1] = false;
	for(int i = 2; i < 1000; i++){
		if(t[i])
			for(int j = 2 * i; j < 1000000; j += i){
				t[j] = false;
			}
	}

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

	return 0;
}

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

int status[1000000];

int main()
{
	int t, sq, i, j, count=0;

	scanf("%d",&t);

	sq=sqrt(t);

	for(i=0;i<=t;i+=2)
	{
	    status[i]=1;
	}
    status[1]=1;
    status[2]=0;
	for(i=3;i<=sq;i+=2)
	{
	    if(status[i]==0)
	    {
	        for(j=i*i;j<=t;j+=i)
    	    {
    	        status[j]=1;
    	    }
	    }
	}

	for(i=0;i<=t;i++)
	{
	    if(status[i]==0)
	    {
            count++;
	    }
	}

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

	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

void Eratosthenes(int n,vi& primes)
{
	primes.assign(n+1,0);
	repi(i,2,n+1)
		primes[i]=1;
	repi(i,2,n+1){
		if(primes[i]==0)
			continue;
		for(int j=i+i;j<=n;j+=i)
			primes[j]=0;
	}
}

int main()
{
	for(int n;cin>>n;){
		vi primes;
		Eratosthenes(n,primes);
		cout<<count(allof(primes),1)<<endl;
	}
	
	return 0;
}