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>
using namespace std;

#define out cout 
#define in cin
#define el endl

#define rep(i, N) for (int i = 0; i < N; i++)
#define mito(N) cout << N << endl

bool f[1000001] = {false};

int main()
{
	for (int i = 2; i * i < 1000001; i++){
		for (int j = i * i; j < 1000001; j += i){
			f[j] = true;
		}
	}

	int n;
	while (in >> n){
		int c = 0;
		for (int i = 2; i <= n; i++){
			if (!f[i])c++;
		}
		mito(c);
	}

	return (0);
}

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

using namespace std;

#define max 999999 + 1

int main(void){

	vector< bool > table( max, true );
	vector< int > p( max, 0 );
	table[0] = false;
	table[1] = false;

	for( int i = 2; i < max; i++ ) {
		if( table[i] == false ) continue;
		for( int j = 2 * i; j < max; j+=i ) {
			table[j] = false;
		}
	}

	for( int i = 1; i < max; i++ ) {
		p[i] = p[i - 1] + table[i];
	}

	int n;
	
	while( scanf("%d", &n ) != EOF ) {
		cout << p[n] << endl;
	}

    return 0;
}

C++: /*
Volume0-0009
*/
#include <iostream>
#include <stdlib.h>
#include <string.h>

#define N 1000000
#define TRUE (int)(0==0)
#define FALSE !TRUE

using namespace std;

int main(int argc, char *argv[]){
  int f[N];

  //  memset(f, TRUE, N);
  f[0]=FALSE;
  f[1]=FALSE;
  for (int i=2; i<N; i++)
    f[i] = TRUE;

  for (int i=2; i<N; i++){
    if (f[i] == TRUE ) {
      for (int j=i+i; j<N; j+=i){
	f[j] = FALSE;
      }
    }
  }
  int n;
  while (cin >> n) {
    int m = 0;
    for (int i=1; i<=n; i++){
      if (f[i]){
	m++;
      }
    }
    cout << m << endl;
  }
 
  exit(0);
}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
	int a[1000000];
	a[0]=1;
	a[1]=1;
	for(int i=2;i<1000000;i++){
		if(a[i]==0){
			for(int j=i;j<1000000;j+=i){
				a[j]=1;
			}
		}
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=0;i<b;i++){
			if(a[i]>b)break;
			else {
				if(a[i]==1) c++;
			}
		}
		cout<<c<<endl;
	}
}

C++: #include<stdio.h>
int count = 0;
int IsPrime(int n){//試し割り
	int i;
	if(n < 2)
		return 0;
		
	else if(n==2){
		count++;
	}
	
	if(n % 2==0)
		return 0;
		
	for(i = 3; i * i <= n; i+=2)
		if(n % i == 0)
			return 0;
			
	count++;
}
int main(){
	int i;
	scanf("%d",&i);
		while(1){
			IsPrime(i);
			i--;
			if(i == 0){
				printf("%d\n",count);
				break;
			}
		}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#define STA 1000000
using namespace std;

bool prime[STA];

int main(){
    memset(prime,true,sizeof(prime));
    for(int i=2;i<STA/2;i++){
        for(int j=2;i*j<STA;j++) prime[i*j] = false;
    }
    int n;
    while(cin >> n){
        int cnt = 0;
        for(int i=2;i<=n;i++){
            if(prime[i]) cnt++;
        }
        cout << cnt << endl;
    }
}

C++: #include <stdio.h>

int main(void){
    int n;
    int cnt;
    int prm;

    while (scanf("%d", &n)!= EOF){
        cnt = 0;
        for(int i=2; i<=n; i++){
            prm=1;
            for (int j=2; j*j<= i; j++){
                if (i%j==0){
                    prm=0;
                    break;
                }
            }
            cnt+=prm;
        }
        printf("%d\n", cnt);
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(int argv,int* argv[]){
unsigned x[30];
int count=0;
for(int i=0;i<argv;i++){
cin>>x[i];
}
for(int i=0;i<argv;i++){
for(int j=1;j<x[i];j++){
if(x[i]%j!=0)
count++;
}
cout<<count<<endl;
count=0;
}
return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	int n;
	while(std::cin>>n){
		int ans=0;
		std::vector<int> vec(n+1);
		for(int i=0;i<=n;i++)vec[i]=1;
		vec[0]=vec[1]=0;
		for(int i=2;i<=n;i++){
			if(vec[i] == 1){
				ans++;
				for(int j = 2 * i ; j <= n ; j += i){
					vec[j]=0;
				}
			}
		}
		std::cout<<ans<<std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <bitset>
#include <fstream>
#include <math.h>

using namespace std;

#define NUM_LIMIT 1000000   // numbers < NUM_LIMIT

int getNumOfPrimes(bitset<NUM_LIMIT> &isPrime, int last_limit, int limit){
    int cnt = 0;
    for (int i = 2; i <= limit; i++){
        if (!isPrime[i]) continue;  // skip non prime numbers
        cnt ++;
        // cross out the multiples of the number
        for (int j = max(2.0,ceil((double)last_limit/i)); i*j <= limit; j++){
            isPrime[i*j] = 0;
        }
    }
    return cnt;
}

int main(){
    //ifstream cin("input.txt");
    bitset<NUM_LIMIT> isPrime;
    isPrime.set();  // set all bits to 1
    
    // input data
    int number;
    int max_num = 0;
    while(cin >> number){
        int cnt = 0;
        if (number > max_num){
            cnt = getNumOfPrimes(isPrime, max_num+1, number);
            max_num = number;
        } else {
            cnt = getNumOfPrimes(isPrime, number+1, number);
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int main(void){
  int n;
  while(cin >> n){
    if(n < 3){
      if(n < 2){
	cout << 0 << endl;
      }else{
	cout << 1 << endl;
      }
    }
    for(int i = 3; i <= n; i += 2){
      bool flag = true;
      for(int j = 3; j <= sqrt(i); j += 2){
	if(i % j == 0){
	  flag = false;
	}
      }
      if(flag)
	ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#define MAX_V 1000000
int prime[MAX_V + 1];
int sum[MAX_V + 1];
int main(){
  int n, i, k;
  /*??¨????????????????????????*/
  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;i++){
    sum[i+1] = sum[i]+prime[i+1];
  }
  /*?´???°?????°???????????????*/
  while(scanf("%d", &n) == 1){
    printf("%d\n", sum[n]);
  }
  printf("%d %d %d\n", n,prime[MAX_V], sum[MAX_V]);
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = int(1e6) + 5;

uint64_t flag[MAX_N];


void set_f(uint64_t i){
    flag[i>>6] &= ~(1ULL<<(i&((1ULL<<6)-1)));
}

bool get_f(uint64_t i){
    return ((flag[i>>6]>>(i&((1ULL<<6)-1)))&1);
}

void sieve(const int64_t n){
    const uint64_t siz = n/2, sqrtN = ceil(sqrt(n)+0.1)/2;
    fill(flag, flag+(siz>>6)+1, -1);
    for(uint64_t i=1ULL; i<=sqrtN; ++i){
        if(get_f(i)){
            const uint64_t p = 2*i+1;
            for(uint64_t j = 2*i*(i+1); j<=siz; j+=p){
                set_f(j);
            }
        }
    }
}

bool isPrime(int n){
    if(n == 2) return true;
    else return n&1 && get_f(n/2);
}

int cum[MAX_N]{};

int main() {
    sieve(MAX_N);
    for(int i=2;i<MAX_N;i++){
        if(isPrime(i))cum[i]++;
        cum[i] += cum[i-1];
    }
    int n;
    while(cin >> n){
        cout << cum[n] << endl;
    }
    return 0;
}

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

bool Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = false;
	for (int i = 0; i < 1000000; i++){
		Eratos[i] = true;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = false;
			}
		}
	}
	int n,res;
	while (scanf("%d", &n)) {
		res = 0;
		for (int i = 0; i < n; i++) {
			if (Eratos[i])
				res++;
		}
		printf("%d\n",res);
	}
	return 0;
}