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<iostream>
#include<string.h>
int main(){int m,n=999999,o,c=n/2+1,d,i,e;bool*v=new bool[c];memset(v,1,c);for(i=m=1;i<499;){for(m=i++;!v[m];)m++;for(o=m*2+1,d=o*3;d<n+1;d+=o*2)v[d/2]=0;}for(;!(std::cin>>n).eof();){e=n>1;n&1?n:--n;for(i=1;i<n/2+1;)e+=v[i++];printf("%d\n",e);}delete[]v;}

C++: #include<bits/stdc++.h>
using namespace std;

int f[1000001];
int main(){
    fill_n(f,1000001,1);
    f[0]=f[1]=0;
    
    for(int i=2;i<1000001;i++){
        f[i]+=f[i-1];
        if(!f[i])continue;
        for(int j=i+i;j<1000001;j+=i)f[j]=0;
    }
    
    int N;
    
    while(scanf("%d",&N)!=EOF){
        printf("%d\n",f[N]);
    }
    
    return 0;
    
}

C++: #include <iostream>
#define N 100000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<fstream>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<ctime>
#include<climits>
#include<ctype.h>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
#define PI acos(-1.0)
#define eps 1e-12
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ll N = 1e6+1;
const int MOD = 1e9+7;
bool flag = true;
int prime[N];
bool check[N]{0};
int main()
{
	//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
	//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
	//%%%llaa
    int i,j,n,tot=0;
    for(i=2;i<N;i++)
    {
        if(!check[i])
        {
            prime[tot++]=i;
            for(j=i+i;j<N;j+=i)
                check[j]=1;
        }
    }
    while(~scanf("%d",&n)&&n)
    {
        int num=0;
        i=0;
        while(prime[i++]<=n)
            num++;
        printf("%d\n",num);
    }
	return 0;
}


/*

*/

C++: #include<iostream>
#include<cmath>
#include<cstdio>
int main()
{
	using namespace std;
	int a[31]={0,0,1,2,2,3,3,4,4,4,4,5};
	int ans=0,t=0,n,i,j;

	while(scanf("%d",&n)!=EOF)
	{
		if(n<=11) cout<<a[n]<<endl;
		else
			for(j=12;j<=n;++j)
			{
				for(i=2;i<=(int)sqrt(n);++i)
			 		if(j%i==0) 
					{
						t=1;
						break;	
			 		}
				
				if(t==0) a[j]=a[j-1]+1;
			 		else 
					{
						t=0;
						a[j]=a[j-1];
					}	
			}
		
		if(n>11) cout<<a[n]<<endl;	
	}
	return 0;
}

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

bool isPrime(int n){
    if(n==2)
        return true;
    else if(!(n&1))
        return false;
    else if(n == 3 || n == 5 || n == 7)
        return true;
    else if(n%3 == 0 || n%5 == 0)
        return false;
    else{
        int root=sqrt(n);
        for(int i=7; i<=root; i+=2)
            if(n%i==0)
                return false;
    }
    return true;
}

int PrimeCounter(int n){
    int counter=0;
    for(int i=2; i<=n; i++){
        if(isPrime(i)){
            counter++;
        }
    }
    return counter;
}

int main()
{
    int n;
    while(scanf("%d", &n) != EOF){
        printf("%d\n", PrimeCounter(n));
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
bool prime[1000000];
void sieve() {
    fill_n(prime, 1000000, true);
    for (int i=2; i<=1000; ++i) {
        if (prime[i]) {
            for (int j=i*i; j<1000000; j+=i) {
                prime[j] = false;
            }
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

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

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

int main(){

	bool is_prime[1000000];
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n_prime[1000000];
	
	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i]=cnt;
	}
	
	while(true){
	int n;
	cin>>n;
	
	if(cin.eof())
		break;
	
	cout<<n_prime[n]<<endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int N,count=0,k;
	while(k<30){
		cin >> N;
		count = 0;
		if(N<0)	break;
	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;
		k++;
	}
	return 0;
}

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

#define Max 1000000

int isPrime[Max];

int main(){
    int num;
    int i,j;

    //配列の初期化
    isPrime[0] = isPrime[1] = 0;
    for(i = 2; i < Max; ++i){
        isPrime[i] = 1;
    }

    for(i = 2; i < Max; i++){
        if(isPrime[i] == 1){
            if(i % 2 == 0){
                isPrime[i] = 0;
            }else if(i % 3 == 0){
                isPrime[i] = 0;
            }else if(i % 5 == 0){
                isPrime[i] = 0;
            }else if(i % 7 == 0){
                isPrime[i] = 0;
            }
        }
    }

    isPrime[2] = 1;isPrime[3] = 1;isPrime[5] = 1;isPrime[7] = 1;

    while(cin >> num){
        int count = 0;
        for(i = 2; i <= num; ++i){
            if(isPrime[i] == 1){
                count++;
            }
        }
        cout << count << endl;
    }

}

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

using namespace std;

void set_prime_number(bool* array, int num) {

  fill(array, array + num, true);
  array[0] = array[1] = false;
  for (int i = 2; i < num; i++) {
    if (!array[i]) continue;
    for (int j = i * 2; j < num; j += i) {
      array[j] = false;
    }
  }

}

int main() {
  bool prime_number[999999];
  int num;
  int nump=0;
  int cnt=0;

	while(scanf("%d",&num)!=EOF){
	  set_prime_number(prime_number,num);
	 for (int i = 0; i < num; i++) {
		 if (prime_number[i]){cnt++;}
	 }
	 printf("%d",cnt);
	 cnt=0;
	}


  return 0;
}

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

using namespace std;

int A[1000000];
int Eratosthenes(int n)
{
	int mama = 0;
	for (int i = 0; i < n; i++)
	{
		A[i] = 1;
	}
	for (int i = 2; i < sqrt(n); i++)
	{
		if (A[i])
		{
			for (int j = 0; i*(j + 2) < n; j++)
			{
				A[i*(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < n; i++)
	{
		if (A[i])
		{
			mama++;
		}
	}
	return mama;
}

int main()
{
	int n;

	while ((scanf("%d",&n))!= -1)
	{
		printf("%d\n", Eratosthenes(n+1));
	}
	return 0;
}