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 <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn=1e6+10;
bool prime[maxn];
int sum[maxn];

void isprime()
{
    memset(prime,true,sizeof(prime));
    for(int i=2;i<=1e3;i++)
    {
        if(prime[i])
        {
            for(int j=i*i;j<1e6;j+=i)
                prime[j]=false;
        }
    }
}

void add()
{
    memset(sum,0,sizeof(sum));
    for(int i=2;i<maxn;i++)
    {
        sum[i]=sum[i-1];
        if(prime[i])
            sum[i]++;
    }
}

int main()
{
    int n;
    isprime();
    add();
    while(scanf("%d",&n)!=EOF)
        printf("%d\n",sum[n]);
    return 0;
}

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 );
    for ( unsigned int i = 2; i < n; ++i )
    {
        for ( unsigned int j = 2; i*j <= n; ++j )
        {
            memo_prime.at(i*j) = false;
        }
    }
    memo_prime.at(0) = memo_prime.at(1) = false;
    memo_prime.at(2) = true;
    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 <stdio.h>

int check_prime(int a)
{
   int c;

   for ( c = 2 ; c <= a-1; c++ )
   {
      if ( a%c == 0 )
        return 0;
   }
      return 1;
}

int main ()
{
    int  n=0,i=0,prime=0,result=0;

   while( scanf("%d",&n) != EOF)
{
 for(i=2;i<=n;i++)
 {

   result = check_prime(i);

   if ( result == 1 )
     prime = prime +1;
 }
 printf("%d",prime);
 printf("\n");
 prime=0;
}
 return 0;
}

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

int MAX = 1000001;
int prime[1000001] = {};

void make_prime(){
  int i, j;

  for (i = 2; i < MAX; i++) {
    prime[i] = 1;
  }

  for (i = 2; i * i < MAX; i++) {
    if (prime[i]){
      for (j = i * 2; j < MAX; j += i) {
        prime[j] = 0;
      }
    }
  }
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  make_prime();
  int i, input, count;

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

  return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
//#include<time.h>
using namespace std;

int main()
{
	
	long long int k,p[100000];
	long long int n;
	//time_t time1,time2;
	p[0]=2;
	while(cin>>n){
		//time(&time1);
		if(n<0){
			break;
		}
	k=0;
	int r=(int)sqrt((float)n);
	for(int i=3;i<=r;i++){
		for(int j=0;j<k+1;j++){
			if(i%p[j]==0){
				break;
			}else if(j==k){
				k++;
				//cout<<i<<endl;
				p[k]=i;
			}
		}
	}
	long long int r_k=k;
	for(;r<n;r++){
		for(long int i=0;i<=r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==r_k){
				k++;
				//cout<<r<<endl;
			}
		}
	}
	//time(&time2);
	if(k!=0&&k!=1){
		k+=1;
		cout<<k<</*"ツ古t\t"<<difftime(time2,time1)<<"minutes"<<*/endl;
	}else{
		cout<<k<</*"\t\t"<<difftime(time2,time1)<<"minutes"<<*/endl;
	}
	}
}

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

int p[1000000],size;

bool isPrime(int x){
	for(int i=0;p[i]*p[i]<=x;i++){
		if(x % p[i] == 0) return false;
	}
	return true;
}

void mkPrime(int n){
	size = 0;
	p[size++] = 2;
	for(int i=3;i<=n;i+=2){
		if(isPrime(i)){
			p[size++] = i;
		}
	}
}


int main(void){
	mkPrime(1000020);

	int n;	
	while(cin>>n){
		int ans = 0;
		for(int i=0;p[i]<=n;i++){
			ans++;
		}
		printf("%d\n",ans);
	}

	return 0;
}

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

int main() {
  int n;
  bool is_prime[1000000];
  int count;

  while (1) {
    cin >> n;
    if (cin.eof()) break;
    for (int i=2; i<=n; i++) is_prime[i] = true;

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

    count = 0;
    for (int i=2; i<=n; i++) {
      if (is_prime[i]) count++;
    }

    cout << count << endl;
  }

  return 0;
}

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

const int N = 19;
int dp[N];
int isprime[N];

int main()
{
    dp[1] = 0;
    for(int i=2;i<N;i++)
    {
        if(!isprime[i])
            for(int j=2*i;j<N;j+=i)
                isprime[j] = 1;
        dp[i] = dp[i-1] + ((isprime[i])?0:1);
    }

    int y;
    while(~scanf("%d",&y))
        printf("%d\n",dp[y]);
    return 0;
}

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

using namespace std;

bool is_prime(const unsigned n);


int main(){
	int n;

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

		for(int number=2;number<=n;number++){
			if(is_prime(number))ans++;
		}
		printf("%d\n",ans);
	}


	return 0;
}

bool is_prime(const unsigned n){
	if(n == 2)return true;

    if(n%2 == 0) return false;

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

    return true;
}

C++: 
#include<iostream>
#define N 1000000


using namespace std;
void PrimeNum(int n,bool Primeif[]){
  for(int i = 2;i*i <= n;i++){
    if(Primeif[i] == true){
      for(int k = 2;k * i <= n;k++){
	Primeif[k*i] = false;
}
    }
  }
}
int main(){
  int n,num;
  bool Primeif[N+1];
  Primeif[1] = false;
  for(int i = 2;i < N;i++){
    Primeif[i] = true;
  }
  PrimeNum(N+1,Primeif);
  
  while(cin >> n){
    num = 0;
    for(int i = 0;i < n;i++){
      if(Primeif[i] == true){
	num = num+1;
      }
    }
     cout << num << endl;
     
   } 
    
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

const int inf=100000000;

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int cnt=0;
    for(int i=1; i<=n; i++)
    {
        if(isprime(i)) ++cnt;
    }
    cout<<cnt<<endl;
}