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

int pri[1000000];
int sz;

void get_pri()
{
    sz=0;
    for(int i=2;i<=999999;i++)
    {
        int ok=0;
        for(int j=2;j*j<=i;j++)
            if(i%j==0){
                ok=1;
                break;
            }
        if(ok==0)
            pri[sz++]=i;
    }
}

int main()
{
    int n;
    get_pri();
    while(scanf("%d",&n)!=EOF)
    {
        int pos=lower_bound(pri,pri+sz,n)-pri;
        if(pri[pos]==n)
            printf("%d\n",pos+1);
        else
            printf("%d\n",pos);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n[99999],j,o=0;
	for(int i=2;i<=99999;i++){
		for( j=2;j<i;j++){
			 if(i%j==0)break;
		}
		if(i == j)n[i]=1;
		else n[i]=0;
	}	
	cin>>a;
	for(int k=2;k<=a;k++) if(n[k]) o++;
	cout<<o<<endl;
}

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

vector<int> sieve;

void make_prime(int n){
  bool a[1000000];
  for(int i = 0; i < 1e6; i++)a[i] = false;
  a[0] = true;
  a[1] = true;
  for(int i = 2; i <= n; i++){
    if(a[i])continue;
    sieve.push_back(i);
    for(int j = i; j <= n; j += i){
      a[j] = true;
    }
  }
}
int main(){
  int n;
  cin >> n;
  make_prime(n);
  cout << sieve.size() << endl;
}

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

bool sieve[1000000];
void makesieve();

int main()
{
	makesieve();
	while(1)
	{
		int n,ans=0;
		std::cin>>n;
		if(std::cin.eof())break;
		for(int i=0;i<=n;i++)
		{
			ans+=sieve[i]?1:0;
		}
		std::cout<<ans<<std::endl;
	}
	return 0;
}

void makesieve()
{
	memset(sieve,-1,sizeof(sieve));
	sieve[0]=false;sieve[1]=false;
	for(int i=2;i<1000000;i++)
	{
		for(int j=i*2;j<1000000;j+=i)
		{
			sieve[j]=false;
		}
	}
}

C++: #include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<set>
#include<cmath>

#define REP(i,s,e) for(int i=int(s);i<int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

using namespace std;

int a[1000000];

bool p(int n){
int m;
for(int i=2;i<=n;i++){
if(n%i==0){ m=i; break;
	}
}
if(m==n) return true;
else return false;
}

int main(){

int n;
while(1){

cin >> n;

if(cin.fail()) break;

int f=floor(sqrt(1.0*n));
int c=floor(sqrt(1.0*n)+1);

for(int j=c;j<=n;j++) a[j]=j;


int x=0;
for(int i=2;i<=f;i++){

	if(p(i)){
	x++;
	for(int j=c;j<=n;j++){
	if(a[j]%i==0 && a[j]!=0) a[j]=0;
	}
	}

}
int y=0;
for(int i=c;i<=n;i++){
	if(a[i]!=0) y++;
}

	cout << x+y << endl;

}

	return 0;
}

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

int eratos(int n) {
	int cnt = 0;
	vector<bool> is_prime(n+1,true);
	is_prime[0] = is_prime[1] = false;
	for (auto i = 2; i <= n; i++) {
		if (is_prime[i]) {
			++cnt;
			for (auto j = 2*i; j <= n; j += i)
				is_prime[j] = false;
		}
	}
	return cnt;
}

int main() {
	for (int n; cin>>n; cout<<eratos(n)<<endl);
	return 0;
}

C++: #include <iostream>
#include <list>
#include <algorithm>

int main(){
	int NUM;
	while(std::cin >> NUM){
		std::list<int> numList,primeList;
		for(int i=2;i<=NUM;++i){
			numList.push_back(i);
		}
	
		for(int i=numList.front();i<std::sqrt(NUM);i=numList.front()){
			primeList.push_back(i);
			numList.erase(std::remove_if(numList.begin(),numList.end(),[&](int num){return num%i==0;}),numList.end());
		}
// 		std::copy(numList.begin(),numList.end(),std::back_inserter(primeList));
		int cnt=numList.size()+primeList.size();	
		std::cout << cnt << std::endl;

// 		std::cout << primeList.size() << std::endl;
		}
	return 0;
}

C++: #include<iostream>
#include<string.h>
int main(){bool*v=new bool[1000000];for(int m,n,o,c,d,e,i;!(std::cin>>n).eof();){if(n<3)e=n>1;else{memset(v,1,c=(n&1?n:--n)/2+1);for(i=m=e=1;i<c;i++){for(m=i;m<c&&!v[m];)m++;if(m==c)break;e++;for(d=o=m*2+1;d<n+1;d+=o*2)v[d/2]=0;if(n<o*o)break;}for(i=1;i<c;)e+=v[i++];}printf("%d\n",e);}delete[]v;}

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

using namespace std;

int main(void){
  const int n = 1000000;
  bool* check_A = (bool*)malloc(sizeof(bool)*n);
  int*  num_A   = (int*)malloc(sizeof(int)*n);
  int N = 0, temp = 2;
  memset(check_A, true, n);
  check_A[0] = false;
  check_A[1] = false;
  num_A[0] = 0;
  num_A[1] = 0;
  for(int i = 0; i < n; i++){
    if(check_A[i]){
      for(;temp < i;temp++){
	num_A[temp] = N;
      }
      temp++;
      num_A[i] = ++N;
      for(int j = 2; i*j < n; j++){
	check_A[i*j] = false;
      }
    }
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}

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

int main() {
int b[10000];
for (int k=0;k<10001;k++){
	b[k]=0;
}
for (int p=2;p<10001;p++){
int i,a=0 ;
	i=2;
	while(i<p){
		if(p%i==0){
			break;
	}i=i+1;
	}
	if (i==p){
		a=1;
	}
	b[p]=a;
}
int c[10000];
for (int l=0;l<10001;l++){
	c[l+1]=c[l]+b[l+1];
}
int r;
while(cin>>r){
	cout<<c[r]<<endl;
}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999

using namespace std;

typedef long long ll;

vector<int>primenumber;
int d[1050000];

int main()
{
	int n;
	
	primenumber.push_back(2);
	d[2] = 1;

	int maxn = 0;

	while (cin >> n) {
		if (maxn<n) {
			for (int i = max(maxn+1,3); i <= n; i++) {
				int ope = 1;
				for (int j = 0; j < primenumber.size(); j++) {
					if (primenumber[j] * primenumber[j] > i)break;
					if (i%primenumber[j] == 0) {
						ope = 0;
						break;
					}
				}
				if (ope == 1)primenumber.push_back(i);
				d[i] = primenumber.size();
			}
			maxn = n;
		}
		cout << d[n] << endl;
	}
	
	return 0;
}

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

using namespace std;

int main() {
  bitset<1000000> primes;
  int i, j, n, ans;
  for (n = 0; n <= 999999; n++) {
    primes.reset();
    for (i = 2; i <= n; i++)
      if (primes[i] == false)
	for (j = i + i; j <= n; j += i)
	  primes[j] = true;
    cout << n == 0 ? 0: n - primes.count() - 1 << endl;
  }
  return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

int main()
{
    int n;
    while (scanf("%d", &n) != EOF) {
        cout << sieve(n) << endl;
    }
    return 0;
}

C++: #include<stdio.h>
 
int main(){
	int a, count = 1, i, j, k = 0;
	while(scanf("%d", &a) != EOF){
		if(a = 1){
			printf("0\n");
			continue;
		}
		for(i = 3; i <= a; i += 2){
			for(j = 3; j < i; j += 2){
				if(i % j == 0){
					k = 1;
					break;
				}
			}
			if(k == 0) count++;
			k = 0;
		}
		printf("%d\n", count);
		count = 1;
	}
	return 0;
}