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>

using namespace std;

bool isPrime(int n){
	
	if (n == 1)
		return false;
	if (n == 2)
		return true;

	for (int i = 2; i*i <= n; ++i){
		if (n%i == 0)
			return false;
	}
	return true;
}

int main(){
	int n;

	while (cin >> n){
		int c = 0;
		while (--n){
			if (isPrime(n+1))
				++c;
		}
		cout << c << endl;
	}
	return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;
 
 int arr[1000005]={0};
 
 bool isPrime(int x)
 {
   for(int i=3;i<=(int)(sqrt(x));i=i+2) 
   {
     if(x%i==0) return false;        
   }    
   return true;
 }
 
 int main()
 {
   int n;
   while(cin>>n)
   {
      if(n==1) cout<<"0"<<endl;
      else if(n==2) cout<<"1"<<endl;
      else if(arr[n]!=0) cout<<arr[n]<<endl;
      else
      {
        int count=1;
        for(int i=3;i<=n;i++)
        { 
          if(isPrime(i))
          { 
            count++;
            arr[i]=count;
          }
        }
        cout<<count<<endl;
      } 
   }
   //while(1);      
   return 0;    
 }

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)

using namespace std;

int main (void){
    
    int number[40] = {0};
    int answer[40] = {0};
    int i = 0,j = 0,k = 0;
    while(cin >> number[i])
    {
        for(k = number[i];k>1;k--)
            for (int l = 2; l<k; l++)
            {
                if( (k % l ) == 0)
                    break;
                if((k % l ) != 0 && (l == k -1) )
                    answer[i]++;
            }
        i++;
    }
    REP(j,i)
    cout << answer[j]+1 << endl;
    return 0;
    
}

C++: // 2014/04/27 Tazoe

#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 <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int n;

	while (cin >> n) {
		int counter = 0;

		for (int i = 2; i <= n; i++) {
			int kari = 1;
			for (int j = 2; j < i; j++) {
				kari = i % j;
				if(kari == 0) {
					break;
				}
			} if (kari != 0) {
				counter++;
			}
		}
		cout << counter << endl;
	}

	return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int pn(int a[],int n){
  int i,j;
  a[0]=a[1]=0;
  for(i=2;i<n;i++)
    a[i]=i;
  for(i=2;i*i<n;i++){
    if(a[i]){
      for(j=i*i;j<n;j+=i)
        a[j]=0;
    }
  }
  j=2;
  for(i=0;j<n;i++){
    a[i]=a[j];
    for(j++;j<n&&a[j]==0;j++);
  }
  return i;
}
int main(){
  int i; 
  int a[1000000];
  a[pn(a,1000000)]=1000000;
  int n;
  while(cin>>n){
    for(i=0;a[i]<=n;i++);
    cout<<i<<endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define N 999999
bool num[N];

void furui(){
  long int i;
  int divide;
  int rt = (int) sqrt(N);
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for(divide = 2; divide <= rt; divide++){
    if(num[divide] == false) continue;
    for( i = 0; i < N; i++){
      if(i % divide == 0){
        num[i] = false;
      }
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0; ;i++){
      c = getchar();
      if(c == EOF || c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == 1) count++;
    }
    printf("%ld\n", count);
    if(c == EOF) break;
  }
  return 0;
}

C++: #include<iostream>
#include<math.h>
main(){
	int i,j,n,p[1000000];
	std::cin>>n;
	for(i=2;i<=n;i++)
		p[i]=1;
	for(i=2;i<n;i++)
		for(j=2;i*j<=n;j++)
			p[i*j]=0;
	j=0;
	for(i=2;i<n;i++)
		j+=p[i];
	std::cout<<j<<std::endl;
}

C++: #include <iostream>
#include <set>
using namespace std;
int main() {
  long n;
  set<long> primes;
  primes.insert(2);
  while (cin >> n) {
    for (int i = 3; i <= n; i += 2) {
      bool prime = true;
      for (long j : primes)
        if (i % j == 0) {
          prime = false;
          break;
        }
      if (prime) primes.insert(i);
    }
    int x = 0;
    for (long j : primes)
      if (j <= n) x++;
    cout << x << endl;
  }
}

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

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*j<=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>
#include <vector>
#include <algorithm>

int count_prime( unsigned int const& n )
{
    if ( n <= 0 || 1000000 <= n ) return -1;
    std::vector<bool> memo_prime( n+1, true );
    memo_prime.at(0) = memo_prime.at(1) = false;
    for ( unsigned int i = 2; i < n; ++i )
    {
        for ( unsigned int j = 2; i*j <= n; ++j )
        {
            memo_prime.at(i*j) = false;
        }
    }
    return std::count( memo_prime.begin(), memo_prime.end(), true );
}

int main()
{
    int n;
    while( std::cin >> n )
    {
        std::cout << count_prime(n) << std::endl;
    }
    return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
int p(long x)
{
    long i,j=sqrt(x),k=1;
    for(i=2;i<=(j);i++)
    {
        if(x%i==0){
            k=0;
            //return k;
        break;

        }
    }
    if(k==1)return 1;
    else return 2;
}
using namespace std;
int main()
{
    double a,b,c,i,n,s=0;

    while(cin>>n){
        s=0;
    //a=sqrt(n);
    for(i=2;i<=n;i++)
    {
        if(p(i)==1){s++;}
    }
    cout<<s<<endl;
    }


    return 0;
}