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

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;

while(~scanf("%d",&n)){
int res=0;
for(int i=2;i<=n;i++){
if(is_prime(n)) res++;
}
printf("%d\n",res);
}
}

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

int main(){
  bool a[1000000];

  a[0]=a[1]=false;
  for(int i=2;i<1000000;i++){
    a[i]=true;
  }

  for(int i=2;i*i<1000000;i++){
    if(a[i]){
      for(int j=i*i;j<1000000;j+=i){
        a[j]=false;
      }
    }
  }

  int n[1000000];

  int tmp=0;
  for(int i=0;i<1000000;i++){
    if(a[i]){
      tmp++;
    }
    n[i]=tmp;
  }

  while(true){
    int m;
    cin>>m;

    if(cin.eof()){
      break;
    }

    cout<<n[m]<<endl;

  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int main(k<30){
	int N,count=0,k;
	while(){
		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<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool prime[1000100]={0};
int main(){
    int N;
    prime[1]=1;
    for(int i=2;i*i<1000000;i++){
        if(prime[i]==0){
            for(int j=i;j<1000000;j+=i){
                prime[j]=1;
            }
        prime[i]=0;
        }
    }
    while(~scanf("%d",&N)){
        int cnt=0;
        for(int i=1;i<=N;i++){
            if(prime[i]==0)cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

#define Max 1000000

int isPrime[Max];

int main(){
    int num;
    int i;

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

    for(i = 4; i < Max; ++i){
        if(i % 3 == 0){
            isPrime[i] = 0;
        }
    }

    for(i = 6; i < Max; ++i){
        if(i % 5 == 0){
            isPrime[i] = 0;
        }
    }

    for(i = 8; i < Max; ++i){
        if(i % 7 == 0){
            isPrime[i] = 0;
        }
    }

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

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

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i;
	if(x == 2){
 		return 1;
	}
  	if(x<2||x%2==0){
		return 0;
	}
	i = 3;
	while( i <= sqrt(x) ){
		if(x%i==0){
			return 0;
		}
		i = i + 2;
	}
	return 1;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i++){
			if(isprime(i)){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <array>
#include <cstdlib>
#include <cmath>

int main() {
	std::array<bool, 1000000> is_prime_table = { false, false, true };
	for( int i=3; i<=is_prime_table.size(); i+=2 ) {
		is_prime_table[i] = [&i]() -> bool
		{
			for( int j=3; j<=std::sqrt(i); j+=2 )
				if ( i % j == 0 )
					return false;
			return true;
		}();
	}
	
	int num = 0;
	while( std::cin >> num ) {
		int result = num > 1 ? 1 : 0;	// 2
		
		for( int i=3; i<=num; i+=2 )
			if ( is_prime_table[i] )
				++result;

		std::cout << result << std::endl;
	}
}

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

int a[999999]={};

int main(){
	int n,ans=0;
	vector<int> v;
	for(int i = 2; i*i < 999999; i++){
		for(int j = 0; j < 999999; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		v.push_back(n);
	}
	for(int i = 0; i < v.size(); i++){
		for(int j = 2; j <= v[i]; j++){
			if(a[j]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

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

int Prime_number(int n){
	int i = 2;
	int ans = 0;

	while(n >= 2){
		while(1){
			if(i == n){
				ans++;
				break;
			}else if(n % i == 0){
				break;
			}
				i++;
		}
		if(n % 2 == 0)
			n--;
		else
			n -= 2;
		i = 2;
	}

	return ans;
}

int main(){
	int n;

	while(cin >> n){
		if(n == 1){
			cout << "0" << endl;
		}else if(n == 2){
			cout << "1" << endl;
		}else{
		cout << Prime_number(n) << endl;
		}
	}

}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

const int size=1000000;
vector<int> map(size,1);
void sieve(int p)
{
    for(int j=p*2;j<size;j+=p)
    {
        map[j]=0;
    }
}
int main(void)
{
    int n;
    scanf("%d",&n);
    map[0]=0;
    map[1]=0;
    sieve(2);
    sieve(3);
    for(int i=7;i<1000;i+=6)
    {
        sieve(i);
        sieve(i+4);
    }
    printf("%d\n",count(map.begin(),map.begin()+n+1,1));
    return 0;
}

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

int main()
{
	const int N = 1000000;
	static bool P[N];
	for ( int i=2; i<N; i++)
		P[i]=true;
	for(int i=2; i*i<N; i++ )
	if(P[i])
		for(int j=i+i;j<N;j+=i)
			P[j]=false;

	int n;
	while(cin>>n)
	{
		int c=0;
		for ( int i=0; i<=n; i++ )
			if (P[i])
				c++;
		cout<< c<<endl;
	}
	return 0;

}

C++: #include <stdio.h>

int main(void){
	bool a[1000000];
	int n = 0;
	int c = 0;
	while(scanf("%d", &n) != EOF){
		switch(n){
		case 1:
			c = 0;
			break;
		case 2:
			c = 1;
			break;
		default:
			c = 1;
			for(int i=3; i<=n; i+=2){
				a[i] = true;
			}
			for(int i=3; i<=n; i+=2){
				if(a[i] == false){ continue; }
				c++;
				for(int j=i; j<=n; j+=i){
					a[j] = false;
				}
			}
			break;
		}
		printf("%d\n", c);
	}
	return 0;
}

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

int main(){
  bool prime[1000000];
  prime[0]=false;prime[1]=false;
  for(int i=2;i<1000001;i++){
    prime[i]=true;
  }

  for(int i=2;i<=sqrt(999999);i++){
    if(prime[i]){
      for(int j=1;j*i<=999999;j++){
        prime[j*i]=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>
#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[1] = 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[j] == 1)
			{
				cnt++;
			}
		}
		printf("%d\n", cnt);
		free(prime);
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
  int n,flag=1,sum = 0;

  while(cin >> n){

    for(int i=2; i <= n; i++){
      if(i != 2 && i%2 == 0) flag = 0;
      else if(i != 3 && i%3 == 0) flag = 0;
      else if(i != 5 && i%5 == 0) flag = 0;
      else{
	for(int j=3; j < i/2; j++){
	  if(i%j == 0 ){
	    flag = 0;
	    j = i/2;
	  }
	}
      }
      if(flag == 1) sum++;
      flag = 1;
    }
    cout << sum <<endl;
    sum = 0;
  }
}