Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [100]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 <vector>
using namespace std;

bool check_prime(int n, vector<int>& prime_vector)
{
	if (n<=1)
		return false;
	if (n==2)
		return true;
	for (int i=0;i<prime_vector.size();i++)
		if (n%prime_vector[i]==0)
			return false;
	return true;
}

vector<int> make_prime(vector<int>& prime_vector, int n)
{
	for (int i=prime_vector[prime_vector.size()-1]+2;i<=n;i+=2)
		if (check_prime(i,prime_vector))
			prime_vector.push_back(i);

	return prime_vector;
}

int count_prime(vector<int>& prime_vector, int n)
{
	int count = 0;
	if (prime_vector[prime_vector.size()-1] >= n)
		for (int i=0;i<prime_vector.size();i++)  {
			count++;
			if (prime_vector[i] >= n) 
				break;		
		}
	else {
		make_prime(prime_vector,n);
		for (int i=0;i<prime_vector.size();i++)  {
			count++;
			if (prime_vector[i] >= n) 
				break;		
		}
	}

	return count;
}

int main()
{
	int n = 0;
	vector<int> result;
	vector<int> prime_vector;
	prime_vector.push_back(2);
	prime_vector.push_back(3);

	while(cin >> n) 
		result.push_back(count_prime(prime_vector,n));

	for(int i=0;i<result.size();i++)
		cout << result[i] << endl;
	
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int prime[1000000];
bool is_prime[1000001];

int sieve(int n){
  int p=0;
  for(int i=0;i<=n;i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<=n;i++){
    if(is_prime[i]==true){
      prime[p++]=i;
      for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
    }
  }
  return p;
}

int main(){
  int n;
  while(scanf("%d",&n)!=EOF)
    cout<<sieve(n)<<endl;
  return 0;
}

C++: ///
// File:  0009.cpp
// Author: ymiyamoto
//
// Created on Wed Nov  8 23:17:22 2017
//

#include <cmath>
#include <cstdint>
#include <iostream>

using namespace std;

bool is_prime(uint32_t val)
{
  for (uint32_t i = 2; i <= sqrt(val); i++) {
    if (val % i == 0) return false;
  }
  return true;
}

int32_t main()
{
  while (true) {
    uint64_t n;
    cin >> n;
    if (cin.eof()) break;

    uint32_t count = 0;
    for (uint32_t i = 2; i <= n; i++) {
      if (is_prime(i)) count++;
    }
    cout << count << endl;
  }

  return 0;
}

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

int main()
{
	int count=0,n;
	prime[0]=1;
	prime[1]=1;

	while(cin>>n)
	{
		int prime[1000001]={0};
		for(int i=2;i<=sqrt(n);i++)
			if(prime[i]==0)
				for(int j=i+1;j<=n;j++)
					if(i%j==0)
						prime[j]=1;
		for(int i=2;i<=n;i++)
			if(prime[i]==0)
				count++;
		cout<<count<<endl;
		count=0;
	}
}

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


int num[1000001]={};
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=1000000;i++)
	num[i]=1;
for(int i=2;i<=1000000;i+=2){
for(int k=2;k<=sqrt((double)i);k+=2){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

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

const int ARR_MAX = 1000000;
int fl[ARR_MAX];
int sm[ARR_MAX+1] = {0};

void init_arr();
void isfl(int);

int main(void) {
  int tag;
  init_arr();

  while(!cin.eof()){
    cin >> tag;
    if(tag == 0) break;
    isfl(tag);
    cout << sm[tag] << endl;
  }
  return 0;
}

void init_arr(){
  for(int i=0;i<ARR_MAX;i++) fl[i] = 1;
}

void isfl(int tag){
  int i,lim,idx = 2;
  fl[0] = 0;
  fl[1] = 0;

  lim = sqrt(tag);

  while(idx <= lim){
    if(fl[idx] == 1) for(i = idx*2;i<=tag;i+=idx) fl[i] = 0;
    idx++;

  }
  for(int i = 2;i<=tag;i++) sm[i] = sm[i-1] + fl[i];
  return;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable:4996)

int main()
{
	
	int num, cnt;
	unsigned int i, j, k, data_num;
	int data[30];
	unsigned int sq_num;
	unsigned int *prime;

	for (data_num = 0; data_num <30; data_num++)
	{
		data[data_num] = -1;
		scanf("%d", &data[data_num]);
		if (data[data_num] < 0)
			break;
	}

	for (k = 0; k < data_num; k++)
	{

		sq_num = (int)sqrt((double)data[k]);
		prime = (unsigned int*)malloc(sizeof(unsigned int) * data[k]);

		prime[0] = 0;
		for (i = 1; i < data[k]; i++)
		{
			prime[i] = 1;
		}

		for (i = 1; i < sq_num; i++)
		{

			if (prime[i] == i)
			{
				for (j = (i + 1); (i + 1)* j <= data[k]; j++)
				{
					prime[(i + 1) * j - 1] = 0;
				}
			}
		}

		cnt = 0; 
		for (i = 0; i < data[k]; i++)
		{
			if (prime[i] == 1)
			{
				cnt++;
			}
		}
		printf("%d\n", cnt-1);
		free(prime);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N;
//??¨????????????????????????
bool is_prime[ 999999 + 1 ];
int E( const int N )
{
    int cnt{};
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//?????????
    }    
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            cnt++;
        }
    }
    return cnt;
}
int main()
{
    while( cin >> N )
    {
        cout << E( N ) << endl;
    }
    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<cstdio>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    int n,ans=0;
    scanf("%d",&n);
    vector<bool> tab(n+1,true);
    int upto=sqrt(n);
    for(int i=2;i<=upto;i++){
        if(tab[i]){
            for(int j=i*2;j<=n;j+=i){
                tab[j]=false;
            }
        }
    }
    for(int i=2;i<=n;i++){
        if(tab[i]) ans++;
    }
    printf("%d\n",ans);
}

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

int main(){
	int a[1000000]{};
	bool b[1000000]{};
	a[1]=0;
	int s=0;
	for(int c=2;c<1000000;c++){
		if(b[c]==false){
			s++;
			for(int d=c*2;d<1000000;d+=c)b[d]=true;
		}
		a[c]=s;
	}
	int k;
	while(cin>>k){
	printf("%d\n",a[k]);	
	}}

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

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

int main()
{
    int i,n,t,c,k;
    while(scanf("%d",&t)==1)
    {
        for(k=0;k<t;k++)
        {
            c=0;
            scanf("%d",&n);

            for(int j=2;j<=n;j++)
            {
                i=prime(j);
                if(i==1)
                c++;
            }

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

    }

    return 0;
}