Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [40]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>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	int n;
	while(cin >> n){
		vi pn(1000000,1);
	pn[0]=0;
	pn[1]=0;
	int ans=0;
	for(int i=2;i<=n;i++){
		if(pn[i]==1){
			for(int j=i+1;j<=n;j++){
				if(!(j%i)){
					pn[j]=0;
				}
			}
		}
	}
	rep(i,n+1){
		if(pn[i])ans++;
	}
	cout << ans << endl;
	}


}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, MAX_N = int(1e6);


int main(){

  int n, i, j, maxin = 2;
  bool jud;
  vector <int> vec;
  for(i = 2;i <= MAX_N; i++){
        jud = 0;
        for(j = 0;  j < vec.size() ; j++){
          if(vec[ j ] * vec[ j ] > i) break;
          if( !( i % vec[ j ] ) ){
            jud = 1;
            break;
          }
        }
        if(!jud)
          vec.push_back( i );
      }
  while(cin >> n){
    cout << upper_bound(vec.begin(), vec.end(), n) - vec.begin()   <<endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(){
  int NUM = 1000000;
  bool prime[NUM];
  prime[0] = false;prime[1] = false;
  for(int i=2;i<NUM;i++)prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;
  int n,c,i;

	int primeNum[NUM];
	for(int i=0;i<NUM;i++){
		if(prime[i])c++;
		primeNum[i] = c;
	}
	while(cin>>n){
		cout<<primeNum[n]<<endl;
		//for(c=0,i=0;i<=n;i++)if(prime[i])c++;
		//cout<<c<<endl;
	}
}

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

int main(){
	int yaku = 0,n,hoge = 0;
	while(cin >> n){
		hoge = 0;
		if(n > 2){
			for(int i = 3;i <= n;i += 2){
				yaku = 0;
				for(int j = 3;j <= sqrt((double)i);j = j + 2){
					
					if(i % j == 0){
						yaku++;
						break;
					}
				}
				if ( yaku == 0)	hoge++;
			}
			
			hoge++;
		}else	hoge == 1;
		cout <<  hoge << endl;

	}

}

C++: #include <iostream>
#include <sstream>
#include <fstream>

#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cctype>

#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
        os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define vv(type,w,h,init) vector<vector<type>>(h,vector<type>(w,init))
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

string const resstr[] = {"Impossible","Possible","No","Yes"};

bool p[100010];

void erato(){
	fill(p, p+100010, true);
	p[0] = p[1] = false;
	
	for(int i=0; i < 100010; i++){
		if(!p[i]) continue;
		for(int j=i+i; j < 100010; j+=i){
			p[j] = false;
		}
	}
}

int main(){
	int n;
	erato();
	while(cin >> n){
		int count = 0;
		for(int i=0; i <= n; i++){
			if(p[i]) count++;
		}
		cout << count << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

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

  vector<bool> prime(1e6, true);
  prime[0] = prime[1] = false;
  for(int i = 2; i * i < 1e6; ++i) {
    if(prime[i]) {
      for(int j = i * i; j < 1e6; j += i) {
        prime[j] = false;
      }
    }
  }

  vector<int> cnt(1e6, 0);
  for(int i = 1; i <= 1e6; ++i) {
    cnt[i] = cnt[i - 1] + prime[i];
  }

  int n;
  while(cin >> n, !cin.eof()) {
    cout << cnt[n] << endl;
  }
}

C++: #include<stdio.h>

int main(void)
{
	int data,i=0,j=2,k=0,l=0,kai[100]={0},s[10000]={0};

	while(scanf("%d",&data) != EOF)
	{
		if(data<0)break;
		else if(data=1)
		{
			kai[k]=0;
		}
		else
		{
			for(i=2;i<data;i++)
				s[i]=i;
		
			for(i=2;i*2<data;i++)		
			{
				for(j=2;j*i<data;j++)				
					s[j*i]=0;
			}
			for(i=2;i<data;i++)
			{	
				if(s[i]!=0)
				{
					l+=1;
				}
			}
		}
		kai[k]=l;
		k+=1;
	}

  for(j=0;j<k;j++)
    printf("%d\n",kai[j]);
  return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,S;
while(cin>>n)
{
	S=0;
	if(n==1)
	{
		cout<<0<<endl;
	}
	if(n>=2)
	{
		S++;
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=i-1;j>1;j--)
		{
			if(i%j==0)
			{
				break;
			}
			if(j==2)
		{
			S++;
		}
		}	
			
	}
	cout<<S<<endl;
}
return 0;
}

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

using namespace std;

int main()
{
    int n;
    bool prime[1000000];

    prime[0] = false;
    for (int i = 1; i < 1000000; i++) 
        prime[i] = true;

    for (int i = 1; i < (int)sqrt(1000000); i++) {
        if (prime[i] == true)
            for (int j = i + 1; (i + 1) * j <= 1000000; j++)
                prime[(i + 1) * j - 1] = false;
    }


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

        for (int i = 0; i < n; i++)
            if (prime[i] == true)
                cnt++;
        cout << cnt << endl;
    }
    
    return 0;
}