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<stdio.h>

int main()
{
    int i,j,n,m,a[10000000],c=0,k,l=0;
    while (scanf ("%d", &n) != EOF) 
    {
    a[c]=n;
    c++;
    }
    for(k=0;k<c;k++)
    {
    l=0;
        for(j=1;j<=a[k];j++)
        {
            m=j;
            for(i=2;i<m;i++)
            {
                if(m%i==0)
                    break;
            }
            if(m==i)
                l++;
        }
         printf("%d\n",l);
    }
    return 0;
}

C++: #include <iostream>

using namespace std;
int main(void){
    int n;
    int count;
    int prime[1000000];
    int i,j;
    while(cin>>n){
        count=0;
        fill(prime,prime+1000000,0);
        prime[0]=prime[1]=1;
        for(i=2;i<=n;i++){
            if(prime[i]==0){
                count++;
                for(j=2*i;j<=n;j+=i){
                    prime[j]=1;
                }
            }
        }
        cout<<count<<endl;
    }
    return(0);
}

C++: #include<iostream>
 
using namespace std;
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#define MAX 1000000
using namespace std;

int main(){
  //bool num[MAX];
  pair<bool,int> num[MAX];
  int input=0;
  while(cin >> input){
   int count=0;
  for(int i=2; i<MAX; i++){
    num[i].first=true;
    num[i].second=i;
  }
  for(int i=2;i<input+1;i++){
    if(num[i].first){
      //cout << num[i].second <<",";
      count++;
      for(int j=i+i; j<MAX; j+=i){
        num[j].first=false;
      }
    }
  }
  cout << count << endl;
  }
}

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

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


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


int main() {

	int num;
	int count;
	while (cin >> num) {
		count = 0;
		if (num >= 2)count++;
		for (int i = 1; i <= num; i += 2) {
			if (isPrime(i))count++;
		}
		printf("%d\n", count);

	}

	//system("pause");
	return 0;
}

C++: #include <iostream>
#include <bitset>
#include <vector>
#include <cmath>
#define	MAXPRIME	999999
using namespace std;

typedef unsigned int uint;

void setPrimeFlag(bool *primeFlag, uint maxPrime) {
	uint sq = (uint)sqrt((double)maxPrime) + 1;
	for (uint i = 2; i <= maxPrime; ++i) { primeFlag[i] = true; }
	primeFlag[0] = primeFlag[1] = false;
	for (uint i = 2; i <= sq; ++i) {
		if (primeFlag[i]) {
			for (uint j = i + i; j <= maxPrime; j += i) {
				primeFlag[j] = false;
			}
		}
	}
}

void setPrimeArray(vector<uint> &primeArray, uint maxPrime) {
	bool *primeFlag = new bool[maxPrime + 1];
	setPrimeFlag(primeFlag, maxPrime);

	primeArray.clear();
	for (uint i = 2; i <= maxPrime; ++i) {
		if (primeFlag[i]) {
			primeArray.push_back(i);
		}
	}
	delete [] primeFlag;
}

int main() {
	vector<uint> primeArray;
	setPrimeArray(primeArray, MAXPRIME);

	for (;;) {
		uint n, num;
		cin >> n;
		if (cin.eof()) { break; }

		for (num = 0; num < primeArray.size() && primeArray[num] <= n; ++num);

		cout << num << endl;
	}

	return 0;
}

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

int pn[1000002];

int main(){
int n, Count;
cin.tie(0);
while(scanf("%d",&n)!=EOF){
Count=0;
memset(pn,0,n);
pn[0]=pn[1]=1;
for(int i=2;i<=n;i++) if(!pn[i]) for(int j=1;i*j<=n;j++) pn[i*j]=1;
Count=count(pn,pn+n,0);
cout<<Count<<endl;
}
return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
    int n;
    while (cin >> n){
        int result = 0;
        for (int i = 2; i <= n; i++){
            for (int j = 2; j <= i; j++)
            {
                if (i == j)result++;
                if (i%j == 0)break;
            }
        }
        cout << result << endl;
    }


    return 0;
}

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

int main() {
	int n;
	
	while (cin >> n) {
		bool prime[1000000];
		for (int i = 2;i <= n;i++) {
			prime[i] = true;
		}
		for (int i = 2;i <= sqrt(n);i++) {
			for (int j = i * 2;j <= n;j += i) {
				prime[j] = false;
			}
		}
		int count = 0;
		for (int i = 2;i <= n;i++) {
			if (prime[i] == true) count++;
		}
		cout << count << endl;
	}

}

C++: /// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
/// http://www.tsg.ne.jp/TT/tsg/c/mansaku/P01.html
#include<cstdio>
#include<cmath>

int main(){
    int n, cnt=0;
    while(~scanf("%d", &n)){
        for(int i = 3; i<=n; i+=2){
            int k= 0;
            for(int j=3; j<sqrt(i); j+=2){
                if(i%j==0){
                    k=1;
                    break;
                }
            }
            if(k==0) cnt++;
        }
        printf("%d\n", cnt);

    }

    return 0;
}

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

int main(){
  int a;
  int i, j, k;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt((double)a);
      for(i=2; i<=a_sqrt; i++){
        k=past/i;
        if(k<2) k=2;
        for(j=k; j<=a/i; j++){
          chk[j*i]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

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

int main(){
  bool prime[1000000] = {};
  int sum[1000000]; sum[0] = sum[1] = 0; sum[2] = 1;
  for(int i = 3 ; i < 1000000 ; i += 2 ){
    sum[i] = sum[i + 1] = sum[i - 1];
    if(!prime[i]){
      for(int j = i + i + i ; j < 1000000 ; j += i + i ){
        prime[j] = true;
      }
      sum[i]++;
      sum[i+1]++;
    }
  }

  int n;
  while(cin >> n){
    cout << sum[n] << endl;
  }
}

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

using namespace std;

int setPrimeNumberCount(int n) {
    int count = 0;
    vector<int> primeList;
    bool findList[n+1];
    
    if(n >= 2) {
        primeList.push_back(2);
        count++;
        
        for(int i = 2; i <= n; i++){
            findList[i] = false;
        }
        for(int i = 2; i <= sqrt(n); i++){
            if(findList[i]) {
                continue;
            }
            for(int j = i * 2; j <= n; j += i) {
                if(!findList[j]) {
                    findList[j] = true;
                }
            }
        }
    }
    for(int i = 3; i <= n; i += 2){
        if(!findList[i]) {
            primeList.push_back(i);
            count++;
        }
    }
    return count;
}

int main(void) {
    int n;
    int count = 0;
    
    while(cin >> n) {
        count = setPrimeNumberCount(n);
        cout << count << endl;
        count = 0;
    }
    return 0;
}